Reputation: 49
When i include image in email it shows sending successful but email is not delivered. If i remove image it works successfully and deliver emails. Here is the function from which i am sending email.
$to = $_POST['email'];
$subject = "Invitation";
$from = "Sender Name";
$from_mail = "[email protected]";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$headers .= "From: ".$from." <".$from_mail.">\r\n";
$message = " <div style='font-family:HelveticaNeue-Light,Arial,sans-serif;background-color:#eeeeee'>
<table align='center' width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='#eeeeee'>
<tbody>
<tr>
<td>
<table cellpadding='0' cellspacing='0' width='630px' align='center'>
<tr>
<td>
<div style='border:3px solid #0074B6'>
<a href='http://www.example.com'>
<img src='http://example.com/images/store_logo.png' width='600' height='110' style='padding: 15px 0 0 10px;' alt='Invitation' /> </a>
<hr style='border:2px solid #0074B6;'>
<div style='padding: 5px 20px 0; text-align: justify;'>
<p>
Other text.....
</p>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>";
$sendmail = mail($to,$subject,$message,$headers);
Upvotes: 0
Views: 149
Reputation:
use the PHPMailer script. You sound like you're rejecting it because you want the easier option. Trust me, PHPMailer is the easier option by a very large margin compared to trying to do it yourself with PHP's built-in mail() function. PHP's mail() function really isn't very good.
To use PHPMailer:
require_once('path/to/file/class.phpmailer.php');
Now, sending emails with attachments goes from being insanely difficult to incredibly easy:
$email = new PHPMailer();
$email->From = '[email protected]';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( '[email protected]' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
It's just that one line $email->AddAttachment(); -- you couldn't ask for any easier.
If you do it with PHP's mail() function, you'll be writing stacks of code, and you'll probably have lots of really difficult to find bugs.
Upvotes: 0
Reputation: 370
i am also facing the same problem , you can try one small solution. put your message in single quotes and image tag like this <img src="http://example.com/images/store_logo.png" width='600' height='110' class="CToWUd">
if it stil not work then you can use [PHPMailer][1]
[1]: https://github.com/PHPMailer/PHPMailer its very easy to use
Upvotes: 2