[英]mail function in php not sending headers
我带来了一个共享服务器,并获得了一些存储空间。 当我运行我的网站时,邮件功能完美运行。 邮件已经发送给主题和消息给所有收件人。 但是发送的邮件中提到“发件人:”。 我包含的标头无法正常工作。 我要发送标题Eg:Form:mymail@mysite.com。 我该怎么做?
<?php
$output="";
if(isset($_POST['submit']) && !empty($_POST['message']))
{
$sub=$_POST['subject'];
$msg=$_POST['message'];
$sql = "select email from login where status='client'";
$query = mysqli_query($con,$sql);
$to=array();
while($row = mysqli_fetch_array($query))
{
$to[] = $row['email'];
$parts = implode(',',$to);
$headers = 'From: mymail@mysiet.com;';
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$subject = $sub;
$content = $msg;
}
if(mail($parts,$subject,$content,$headers))
{
$output="mail sent";
}
else
{
$output="Error in connection, Mail could not be sent. Please try again";
}
}
?>
您需要手动指定标题,这是我使用的功能,它可以将精美的内容传递给几乎每个提供商。 您想要的标题是“ From:
和“ Reply-To:
并且我还建议X-Mailer
遵循此处看到的内容,我几年前也通过SO找到了它。
<?php
$to = "user@anotherdomain.com";
$headers = 'From: My Name <email@domain.com.au>' . "\r\n" .
'Reply-To: My Name <email2@domain.com.au>' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'Content-type: text/html; charset=iso-8859-1';
$subject = "My subject line here";
$message = 'Message HTML and Content Here.';
if(mail($to, $subject, $message, $headers)){
// Success Here
}else{
// Failed Here
}
?>
我并不是100%地确定它会像在专用计算机上那样为您工作,我已经说过-我确实在多个域上使用它,并且从未与邮件设置相关的Apache或php配置搞乱。
阅读有关PHP中邮件功能的更多信息: http : //php.net/manual/en/function.mail.php
您可以尝试下面的代码,只是从php.net破译
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
没有话题,但是很好使用PHPMailer 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.