我的PHP应用程序发送的一些电子邮件存在问题。
电子邮件收到空白,并且都会被发送到特定地址。这些电子邮件也被CC控制到我可以控制的地址,并且它们都被正确接收。所有电子邮件都以HTML格式发送。
我无法控制这些电子邮件发送到的远程电子邮件地址,但我100%确定他们会通过某种M $交换垃圾邮件过滤器。它可能是导致数据丢失的过滤器吗?
对此的任何其他想法都会很棒!
答案 0 :(得分:2)
您说所有电子邮件都是以HTML格式发送的。您可能需要发送纯文本以配合它 - 以满足那些不支持HTML的电子邮件客户端。 http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php
这是来自上述链接的复制粘贴:
<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>