我有以下代码
$subject = "Subject Here";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Domain Name <domain@domain.com>' . "\r\n";
$to = $email;
$body = '
My Message here
';
mail($to, $subject, $body, $headers);它可以正确地发送邮件,但当我在gmail中看到详细信息时……它显示了
从域名到myemail@myemail.com日期,2010年5月25日星期二下午12:41主题我的主题在此处邮寄-由mars.myhostingcompany.net
虽然我想在mailed部分中显示我自己的地址,因此它应该是mydomain.com而不是mars.myhostingcompany.net
发布于 2010-05-26 04:11:04
我认为你在共享主机上,所以它显示你的主机电子邮件地址的原因是因为当你配置PHP时,有一个名为"sendmail_from“的设置,这是在你的代码中没有提供地址的情况下发送邮件的默认地址。
您似乎在代码中指定了正确的头文件,所以我只能想到一种可能性(我不能在这台计算机上测试)。尝试删除您的电子邮件地址周围的<>-它可能会尝试将其读取为HTML,因此您将一无所有。这可能发生在Windows计算机上,因为PHP本身解析自定义头,而不是MTA (邮件传输代理),并且PHP将任何<>视为HTML。
我知道它看起来不专业(因为电子邮件客户端在收到电子邮件时不会显示名称),但如果你在Windows机器上运行,除非你切换到另一个邮件包,否则你几乎无能为力。
$subject = "Subject Here";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: domain@domain.com' . "\r\n";
$to = $email;
$body = '
My Message here
';
mail($to, $subject, $body, $headers);发布于 2014-06-14 04:37:32
有两种类型的发送方(From),即MIME标头发送方和envelope发送方。
在mail()函数的第4个参数的头中发送MIME发送者。你做得很好。
带有-f标志的enveloper发送者(当您通过sendmail或sendmail兼容包装器发送电子邮件时可以发送的发送者)是在第五个mail()参数additional_parameters中设置的,其格式与您在命令行上传递的格式相同:-femail@address.tld。
因此,您的mail函数最终将如下所示:
mail($to, $subject, $body, $headers, "-fdomain@domain.com");发布于 2012-02-14 05:05:18
//表单页:
<form method="POST" action="mailer.php">
<p>Please feel free to contact me on the form below or my direct email address: jkench@jasonkench.co.uk<br>
<br><br>
<br>
<br>
<br>
</p>
<table width="327" border="0">
<tr>
<td width="102">Name:</td>
<td width="215"><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td>Company:
<label for="company"></label></td>
<td><input type="text" name="company"></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="email" size="19"></td>
</tr>
<tr>
<td>Telephone No:
<label for="telephone"></label></td>
<td><input type="text" name="telephone"></td>
</tr>
</table>
<p><br>
Enquiry:<br>
<textarea rows="9" name="message" cols="65"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</p>
</form>//PHP邮件页面
<?php
if(isset($_POST['submit'])) {
//SEND TO
// Send the completed form to the below email address:
$to = "myemail@mydomain.co.uk";
//SUBJECT
// Subject of the email form:
$subject = "Jason Kench - Web Developer";
//NAME
//POST the details entered into the name box
$name = $_POST['name'];
//COMPANY NAME
//
$company = $_POST['company'];
//EMAIL
//
$email = $_POST['email'];
//TELEPHONE NUMBER
//
$telephone = $_POST['telephone'];
//MESSAGE/ENQUIRY
$message = $_POST['message'];
//Headers from a online site may help not sure
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//FROM EMAIL ADDRESS:
// Additional headers to change the FROM EMAIL ADDRESS
$headers .= 'From: Web-Contact-Form@mydomain.co.uk' . "\r\n";
// BODY
// This is the body of the message that will be sent to my email address with their details.
$body = "
You have received a message from the online contact form at http://www.jasonkench.co.uk\n
Details Below: \n \n
From: $name\n
Company: $company\n
$headers
Email Address: $email\n
Telephone No: $telephone\n
Message: $message\n";
// FORM SENT
// This will alert the customer the form has been successfully sent.
echo "Your details have been sent, I will contact you within 48 hours.";
// Use the mail function to email the following variables to my $to email address.
mail($to, $subject, $body, $headers);
} else {
// Display error message if there is a problem.
echo "Sorry there seems to be a problem. Please email me direct at: $to thank you.";
}
?>https://stackoverflow.com/questions/2908058
复制相似问题