1

i am trying to send html image mailer using php mail function on linux platform. There is one issue when i am trying to send simple html content then it successfully get delivered to its subscriber. but when i try to send emailer which contains few images then it fails to deliver it. below are two codes 1 by which simple html is delivered. 2 which is not getting delivered.

<?php
$to = "[email protected], [email protected]";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

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

code 2:

<?php
    //change this to your email.
    $to = "[email protected]";
    $from = "[email protected]";
    $subject = "Hello! This is HTML email";

    //begin of HTML message
$message= <<<EOF
<html>
  <body bgcolor="#DCEEFC">
    <center>
        <b>Looool!!! I am reciving HTML email......</b> <br>
        <font color="red">Thanks Mohammed!</font> <br>
        <a href="http://www.maaking.com/">* maaking.com</a>
    </center>
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
  </body>
</html>
EOF;
   //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";

    //options to send to cc+bcc
    //$headers .= "Cc: [email][email protected][/email]";
    //$headers .= "Bcc: [email][email protected][/email]";

    // now lets send the email.
    mail($to, $subject, $message, $headers);

    echo "Message has been sent....!";
?>
4
  • 1
    As a tip, sending mails with PHP is not easy. It would be best to use a libary like Swiftmailer which makes the process a lot easier. Look here: swiftmailer.org/docs/messages.html Commented Sep 28, 2013 at 10:26
  • thanks Reflic but i need to do it using php . I will look and try to use the documentation u provided. But do you have any idea how can i do it using php... Commented Sep 28, 2013 at 10:53
  • possible duplicate: HEREDOC syntax Commented Sep 28, 2013 at 10:55
  • PHP Parse error: syntax error, unexpected T_SL in /root/send_html/sendmailer.php on line 8...this is the error i am getting. Commented Sep 28, 2013 at 16:05

1 Answer 1

2

I corrected the code by which I am able to send image mailer below is the code:

<?php
$to= '[email protected]' . ',';
$to .= '[email protected]';
$sub='test1';
$msg= <<<EOF
   <html>
   <body>
   <table>
     <tr>
      <td><img src="http://d32vlg867bsa1v.cloudfront.net/z/prod/w/2/i/zovi-logo2.png"  />
      </td>
     </tr>
    </table>
    </body>
    </html>
EOF;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: <[email protected]>' . "\r\n";


mail($to,$sub,$msg,$headers);
?>

I am still working to sent highly customized mailer and will describe how it can once I found how it can be done.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.