[英]mail function in php not sending headers
I brought a shared sever, and got a little storage space. 我带来了一个共享服务器,并获得了一些存储空间。 When i run my web site, the mail function works perfectly.
当我运行我的网站时,邮件功能完美运行。 Mail has been sent with subject and message to all receivers.
邮件已经发送给主题和消息给所有收件人。 But the mail which is sent mentioned "From : ".
但是发送的邮件中提到“发件人:”。 Headers what i included are not working.
我包含的标头无法正常工作。 I want to send with my headers Eg:Form: mymail@mysite.com .
我要发送标题Eg:Form:mymail@mysite.com。 How can i do it?
我该怎么做?
<?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";
}
}
?>
You need to manually specify the headers, this is the function I use and it delivers to pretty much every provider beautifully. 您需要手动指定标题,这是我使用的功能,它可以将精美的内容传递给几乎每个提供商。 The headers you want are
From:
and Reply-To:
and I also advise the X-Mailer
follows what is seen here, I found it years ago via SO as well. 您想要的标题是“
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
}
?>
I am not 100% certain it will work for you as I am on a dedicated machine, having said that - I do use it on multiple domains and have never messed with my Apache or php configuration in relation to mail settings. 我并不是100%地确定它会像在专用计算机上那样为您工作,我已经说过-我确实在多个域上使用它,并且从未与邮件设置相关的Apache或php配置搞乱。
Read More about the Mail function in PHP: http://php.net/manual/en/function.mail.php 阅读有关PHP中邮件功能的更多信息: http : //php.net/manual/en/function.mail.php
You can try below code, just ripped from php.net 您可以尝试下面的代码,只是从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";
Off topic but good to use PHPMailer . 没有话题,但是很好使用PHPMailer 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.