简体   繁体   English

PHP Sender电子邮件地址作为电子邮件标题

[英]PHP Sender email address as email title

When we receive messages through our site, the 'sender' of the email is listed as "newwavea@host424.hostmonster.com", rather than the address of the person who submitted a message. 当我们通过我们的网站接收消息时,电子邮件的“发件人”列为“ newwavea@host424.hostmonster.com”,而不是提交消息的人的地址。 Could you check my PHP and see where I've gone wrong? 您可以检查我的PHP并查看我哪里出错了吗? Thanks. 谢谢。 Here's the WEBPAGE LINK 这是网页链接

<?php

if(!empty($_POST['full-name1']) or !empty($_POST['email1']) ) {
    header('Location: success.html');
}

$name = $_POST['full-name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: SSR'; 
$to = 'info@new-wave-academy.com'; // send to this address
$subject = $_POST['subject'];

$body = "From: $name\n
Email: $email\n 
Message:\n $message";

mail($to, $subject, $body); 
header("Location: http://new-wave-academy.com/Contact/success.html"); /* Redirect browser */
exit();
?>

From and Return-path addresses must be set explicitly. 必须明确设置“ From和“ Return-path地址。 PHP will not parse the message body looking for them (why should it?). PHP不会解析消息正文以寻找它们(为什么要这么做?)。 Since you aren't setting any, the system will simply use default value set in server config. 由于您未设置任何设置,因此系统将仅使用服务器配置中设置的默认值。

You can use the $additional_headers parameter for sender and, in many numbers, you can use $additional_parameters for the return address: 您可以将$additional_headers参数用于发件人,并且在许多数量中,可以将$additional_parameters用于返回地址:

bool mail ( string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]] )

( reference ) 参考

Beware though that the underlying mail transport service may or may not allow arbitrary addresses in these fields. 请注意,基础邮件传输服务可能会或可能不允许在这些字段中使用任意地址。

It's also very easy to screw the message format with mail() so I strongly recommend a third party library like Swift Mailer or PHPMailer . 使用mail()固定消息格式也非常容易,因此我强烈建议您使用第三方库,例如Swift MailerPHPMailer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM