PHP mail()函数,gmail作为接收者(noname.txt作为附件而不是文本消息)

时间:2011-10-26 05:36:53

标签: php email gmail

我在通过Php mail()函数向gmail发送电子邮件时遇到问题。我用我的雅虎邮件测试了这个脚本,没有问题(电子邮件正文没有附件)。这是我的代码:

$mailto = "info@email.com";
$charset = "utf-8";
$subject = "subject text";
$content = "text/html";

    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-Type: $content  charset=$charset\n";
    $headers .= "Date: ".date("Y-m-d (H:i:s)",time())."\n";
    $headers .= "From: \"".$mailto."\" <".$mailto.">\n";
    $headers .= "X-Mailer: My Send E-mail\n";
    $message = "message text";

    mail($_POST['posEmail'],$subject,$message,$headers);

4 个答案:

答案 0 :(得分:1)

$headers .= "Content-Type: $content; charset=$charset\n";

内容和字符集之间的分号?

尝试使用\ r \ n结束行,而不是\ n。

答案 1 :(得分:1)

使用phpmailer类,它更安全,更容易使用。它支持附件和类似。

答案 2 :(得分:1)

$headers =  'To: ' . $epost . "\r\n";
$headers .= 'From: ' . $mailto . "\r\n";
$headers .= 'Message-ID: <' . $ordernummer . ">\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable';

这些标题可行。我还收到了一封名为noname.txt的附件。

我添加了Message-IDContent-Transfer-Encoding,从ToFrom中删除了真实姓名,跳过了电子邮件周围的<>,取消了text/plain左右的引号{1}}以及我大写的UTF-8左右。

答案 3 :(得分:-1)

你只需编辑你的php.ini并把它放到

  

SMTP = smtp.gmail.com

     

smtp_port = 25

     

sendmail_from = youremailid@gmail.com

     

Send email using the GMail SMTP server from a PHP page