用户/客户未收到PHP mail()消息?
这是我的内部电子邮件类,它使用PHP mail()发送电子邮件:用户/客户未收到PHP mail()消息?,php,email,paypal-ipn,Php,Email,Paypal Ipn,这是我的内部电子邮件类,它使用PHP mail()发送电子邮件: class Email { public $from = ''; public $from_name = ''; public $reply_to = ''; private $to = ''; private $subject = ''; private $message = ''; private $attachment = ''; private $attac
class Email {
public $from = '';
public $from_name = '';
public $reply_to = '';
private $to = '';
private $subject = '';
private $message = '';
private $attachment = '';
private $attachment_filename = '';
public function __construct($to, $subject, $message, $attachment = '', $attachment_filename = '') {
$this -> to = $to;
$this -> subject = $subject;
$this -> message = $message;
$this -> attachment = $attachment;
$this -> attachment_filename = $attachment_filename;
$this -> from = SITE_EMAIL;
$this -> from_name = SITE_NAME_URL;
$this -> reply_to = SITE_EMAIL;
}
public function mail() {
if (!empty($this -> attachment)) {
$filename = empty($this -> attachment_filename) ? basename($this -> attachment) : $this -> attachment_filename ;
$path = dirname($this -> attachment);
$mailto = $this -> to;
$from_mail = $this -> from;
$from_name = $this -> from_name;
$replyto = $this -> reply_to;
$subject = $this -> subject;
$message = $this -> message;
$file = $path.'/'.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header, '-f'.$this -> from)) {
return true;
} else {
return false;
}
} else {
$header = "From: ".($this -> from_name)." <".($this -> from).">\r\n";
$header .= "Reply-To: ".($this -> reply_to);
if (mail($this -> to, $this -> subject, $this -> message, $header, '-f'.$this -> from)) {
return true;
} else {
return false;
}
}
}
}
您可以看到我正在向站点发送相同邮件正文的两封电子邮件($buyerEmail和$adminEmail)(info@example.com)这是我的电子邮件和买家的PayPal电子邮件
我的网站\u电子邮件(info@example.com)是一封由Google Apps托管的电子邮件,它始终会收到此消息。当我点击邮件标题详细信息时,它是由正确发送的,并由我的网站example.com签署的:
然而,大约30%-50%的客户抱怨在付款后没有收到信息,我不得不手动将收到的信息转发给他们。这令人沮丧,因为:
在这里,什么是保证传递和不被识别为垃圾邮件的最佳做法?我在使用PHP
mail()
和一些未传递的邮件时遇到了问题。我猜当使用mail()
时,标题并不完美。我发现解决这个问题的唯一方法是在服务器上安装PHP Pear邮件库,并使用SMTP和Pear发送电子邮件
您将希望包括其他标题,而不仅仅是下面的标题。这只是一个简单的例子,说明如何通过PEAR和smtp发送电子邮件
require_once "Mail.php";
$from = "Your Name <your@email.com>";
$to = 'to@email.com';
$subject = "Some Subject";
$body = "Some Message";
$host = "smtp.yourhost.com";
$port = "25";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => false));
$mail = $smtp->send($to, $headers, $body);
require_once“Mail.php”;
$from=“您的姓名”;
$to$to@email.com';
$subject=“某个主题”;
$body=“一些消息”;
$host=“smtp.yourhost.com”;
$port=“25”;
$headers=数组('From'=>$From,
'至'=>$至,
“主题”=>$Subject);
$smtp=Mail::工厂('smtp',
数组('host'=>$host,
“端口”=>$port,
'auth'=>false));
$mail=$smtp->send($to、$headers、$body);
注意:您还可以通过定义用户名和密码并设置
auth=>true
来执行经过身份验证的smtp。您最好通过外部smtp服务发送邮件。尝试在您的Google Apps SMTP服务器上使用SwiftMailer。我使用过SPF记录、域密钥等,但仍然无法将邮件发送到Outlook.com地址:(
require_once "Mail.php";
$from = "Your Name <your@email.com>";
$to = 'to@email.com';
$subject = "Some Subject";
$body = "Some Message";
$host = "smtp.yourhost.com";
$port = "25";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => false));
$mail = $smtp->send($to, $headers, $body);