【发布时间】:2009-09-13 01:11:19
【问题描述】:
我有一个 php 脚本,一旦人们提交了一些信息,它就会发送带有附件的电子邮件。我在我的 gmail 收件箱中收到这些电子邮件没有问题。但是,当我使用我的个人电子邮件地址或工作电子邮件地址时,电子邮件永远不会送达。这是我的脚本(如下)或我在服务器上的某些设置的问题吗?我认为这可能是标题的问题,但是每次我更改标题时,它们都会破坏电子邮件,并且所有内容都会出现在邮件正文中。有谁知道如何解决这一问题? 服务器是客户端管理的带有 plesk 控制面板的 linux 服务器,所以我无权访问 php ini 文件。
//define the receiver of the email
$to = 'test@test.com';
//define the subject of the email
$subject = 'Email with Attachment';
//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
$mime_boundary = "<<<--==+X[".md5(time())."]";
$path = $_SERVER['DOCUMENT_ROOT'].'/two/php/';
$fileContent = chunk_split(base64_encode(file_get_contents($path.'CTF_brochure.pdf')));
$headers .= "From: info@example.org.uk <info@poundsandpennies.org.uk>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";
$message = "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "Email content and what not: \r\n";
$message .= "This is the file you asked for! \r\n";
$message .= "--".$mime_boundary."" . "\r\n";
$message .= "Content-Type: application/octet-stream;\r\n";
$message .= " name=\"CTF-brochure.pdf\"" . "\r\n";
$message .= "Content-Transfer-Encoding: base64 \r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= " filename=\"CTF_brochure.pdf\"\r\n";
$message .= "\r\n";
$message .= $fileContent;
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
//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";
【问题讨论】:
-
嗨,德鲁。当您发送到其他非 gmail 帐户时,输出“邮件已发送”或“邮件失败”。您是否尝试发送到另一个 gmail 帐户?
-
每次发送邮件时输出