Search code examples
phpemailsmtpclickatell

PHP integration with Clicatell SMTP API


I am trying to sent up a php that will sent email to Clicatell SMTP api. The idea is simple - making calls using PHP SOAP client to SQL server, getting the reply and the inserting this reply into email body sent to Clicatell server.

<?php

$to = '[email protected]';

$today = strtoupper(date('dMy')); 
$subject = 'Test sms sent on ' . $today;

// API request and response goes here 
//this is how the response from the api looks like

$response ='To:4412345677693\r\nTo:4412345665693\r\nTo:4412375677693\r\nTo:4463879456776\r\n';  

$message = 'api_id: 12345678\r\nuser:user1234\r\npassword:PxAxSxSxWxOxRxD\r\n' . $response . 'Reply: [email protected]\r\ntext:Test Message Using Clickatell api\r\n'; 

$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type:text/html;charset=UTF-8' . '\r\n';
$headers = 'From: [email protected]' . '\r\n' .

mail($to,$subject,$message,$headers);
?>

This should hopefully produce email in plain text looking like:

To: [email protected]

api_id: 12345678
User: user1234
Password: PxAxSxSxWxOxRxD
To:4412345677693
To:4412345665693
To:4412375677693
To:4463879456776
Reply: [email protected]
text: Test Message Using Clickatell api

However I am getting everything on just one line. And help would be appreciated.


Solution

  • Just change the quotes to double quotes to handle control characters properly:

    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8\r\n";
    $headers .= "From: [email protected]\r\n";
    

    The same should be applied to $response and $message. Does it help?