【问题标题】:how to format php email如何格式化php电子邮件
【发布时间】:2014-09-16 09:47:25
【问题描述】:

我会让它变得非常简单。我想通过php发送电子邮件。现在这里是代码。

$line = '\n';
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;       

$to = "forgotten_tarek@yahoo.com";
$subject = "Umrah Booking";
$from = $mailer;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);

这是输出:

Customer Phone: 0712345678\nCustomer Last Name: Showkot

并且电子邮件显示没有发件人。上面写着nobody

我希望电子邮件看起来像:

Customer Phone: 0712345678
Customer Last Name: Showkot

我还想表明该电子邮件来自example@example.com

【问题讨论】:

    标签: php email


    【解决方案1】:

    1) 将'\n' 更改为"\n"。特殊字符(如\n)仅在double-quoted strings 中解释。

    2) 尝试将"From:" 更改为"From: "。或者,也许变量$from 没有价值。

    【讨论】:

    • +1 用于解释为什么,而不仅仅是做什么。我正要评论为什么不同的引号是必要的,但你只是添加了那个。
    • 谢谢...我刚登录说问题解决了!!无论如何,非常感谢:-)
    【解决方案2】:

    您也可以使用 html 邮件,因为您可以发送实际上使用 html 格式化的邮件。这非常简单,yu 几乎可以使用 yu 用于格式化 html 内容的所有标签,甚至 css 也可以被添加..!!您需要添加标题以发送 html 邮件。

    这是一个例子..!

    $to = "sended@test.com";
    $subject = "Test mail";
    $a = "Customer Phone: ";
    $b = "Customer Last Name: ";
    $message = $a.$number.$line.$b.$LastName;  
    $message="
    <html>
    <body>
      <h1>$a</h1>: $number <br> <h1>$b</h1>: $LastName<br>
    </body>
    </html>";
    
    $from = "tester@test.com";
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    
    mail($to,$subject,$message,$headers);
    

    也试试这个。,它会工作的..! :)

    【讨论】:

    • 谢谢它已经成功了!!我已经处理了:-)但是还是谢谢你的关心!!
    【解决方案3】:
    $line = "\n";
    $a = "Customer Phone: ";
    $b = "Customer Last Name: ";
    $message = $a.$number.$line.$b.$LastName;
    
    $to = "forgotten_tarek@yahoo.com";
    $subject = "Umrah Booking";
    $from = $mailer;
    $headers = "From: " . $from. "\r\n".
    'Reply-To: '. $from . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    mail($to,$subject,$message,$headers);
    

    【讨论】:

      【解决方案4】:

      例如可以在message标签中输入html:

      $message = '<html><body>';
      $message .= '<h1>Hello, World!</h1>';
      $message .= '</body></html>';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多