从PHP发送电子邮件

时间:2014-02-17 16:48:30

标签: php

我正在从php表单发送电子邮件,它可以正常传递邮件,但是由于我添加了邮件优先级,因此表单会在同一电子邮件地址之间传递邮件。

示例:

$email = $row['SUBSCRIPTIONS_EMAIL_FROM']; --> subscriptions@example.com

$emailto = $row['SUBSCRIPTIONS_EMAIL_TO']; --> me@example.com

$subject = $row['SUBSCRIPTIONS_1ST_NOTICE_SUBJECT'];

$headers = "From: $email";

$send = mail($emailto, $subject, $body, $headers); 

它使用来自SQL

的给定电子邮件地址来发送和发送电子邮件

但是,因为我为消息优先级添加了额外的标头:

$email = $row['SUBSCRIPTIONS_EMAIL_FROM']; --> subscriptions@example.com

$emailto = $row['SUBSCRIPTIONS_EMAIL_TO']; --> me@example.com

$subject = $row['SUBSCRIPTIONS_1ST_NOTICE_SUBJECT'];

$headers = "From: $email";

$headers = "X-Priority: 1 (Highest)\n"; 

$headers = "X-MSMail-Priority: High\n"; 

$headers = "Importance: High\n";

$send = mail($emailto, $subject, $body, $headers); 

它会在$emailto:电子邮件地址之间发送电子邮件。

任何人都可以帮我吗?

提前致谢。

1 个答案:

答案 0 :(得分:3)

有两件事首先引起了我的注意:

  1. 您多次覆盖$ header:
  2. 您应该使用回车符和新行来分隔“\ r \ n”行。
  3. 而不是:

    $headers = "From: $email";
    $headers = "X-Priority: 1 (Highest)\n"; 
    $headers = "X-MSMail-Priority: High\n"; 
    $headers = "Importance: High\n";
    

    尝试连接并使用行正确的分隔符:

    $headers = "From: $email\r\n";
    $headers .= "X-Priority: 1 (Highest)\r\n"; 
    $headers .= "X-MSMail-Priority: High\r\n"; 
    $headers .= "Importance: High\r\n";