使用php邮件功能发送电子邮件。如果我从电子邮件中删除图像,邮件已成功发送

时间:2016-06-13 09:30:53

标签: php html-email

当我在电子邮件中包含图片时,它显示发送成功但电子邮件未送达。如果我删除图像,它可以成功运行并发送电子邮件。 这是我发送电子邮件的功能。

$to = $_POST['email'];
$subject = "Invitation";
$from = "Sender Name";
$from_mail = "info@example.com";
$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);

2 个答案:

答案 0 :(得分:2)

我也面临同样的问题,你可以尝试一个小解决方案。将您的邮件放在单引号和图片标记中,如<img src="http://example.com/images/store_logo.png" width='600' height='110' class="CToWUd"> 如果它不起作用那么你可以使用[PHPMailer] [1]

[1]:https://github.com/PHPMailer/PHPMailer它非常易于使用

答案 1 :(得分:0)

使用PHPMailer脚本。你听起来像是在拒绝它,因为你想要更简单的选择。相信我,与使用PHP的内置mail()函数自己做的相比,PHPMailer是一个非常大的选择。 PHP的mail()函数确实不是很好。

使用PHPMailer:

  • 从此处下载PHPMailer脚本:http://github.com/PHPMailer/PHPMailer
  • 提取存档并将脚本的文件夹复制到项目中方便的位置。
  • 包含主脚本文件 - require_once('path/to/file/class.phpmailer.php');

现在,发送附带电子邮件的过程非常困难,非常简单:

$email = new PHPMailer();
$email->From      = 'you@example.com';
$email->FromName  = 'Your Name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );

return $email->Send();

这只是一行$ email-&gt; AddAttachment(); - 你不能要求更容易。

如果你使用PHP的mail()函数,你将编写代码堆栈,你可能会有很多很难找到错误。