简体   繁体   English

不发送带有电子邮件标题的php中的电子邮件

[英]not sending email in php with header from email id

I am using the following code along with HTML for header . 我正在使用以下代码以及HTML作为header。

$email="example@example.com"; $ email =“ example@example.com”; in the example and I want to implement variable in its place. 在示例中,我想在其位置实现变量。 Code as posted below but its not showing error nor sending email. 如下所示的代码,但未显示错误或发送电子邮件。

I have tried the following links PHP email form not sending information , PHP Sending Emails with File Attachments - Email Not Sending At All . 我尝试了以下链接, PHP电子邮件表单不发送信息PHP发送带有文件附件的电子邮件-根本不发送电子邮件

I have tried 我努力了

$headers .= "From: <".$email.">\n";

and

$headers .= $email; $ headers。= $ email;

This displays $email in the label from header in email . 这将在email标题中的标签中显示$ email

But its working fine till this line: 但是直到这行它的工作正常:

$headers .= 'From: ' .$email. "\r\n";

This above line is not sending email if I remove this line it works but it does not add From email id to the header. 如果我删除此行,则上面的这一行不发送电子邮件,它可以工作,但不会将“发自电子邮件的ID”添加到标题中。

Please help me out it does not show any error and I have tried many variations to the above code but still stumped. 请帮助我,它没有显示任何错误,我已经尝试了上述代码的许多变体,但仍然受阻。

<?php

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['contact'];

$subject = "feedback";
$question = $_REQUEST['question'];


$body = "<html>
<head>

</html>";
$mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n";
$headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n";
$headers .= 'From:'.$email. "\r\n";


$to ='example@example.com';
mail($to,$subject,$body,$headers);
echo "<script>alert(' message  sent.');</script>";

?>

如果您使用标准邮件功能,请尝试以下操作(不要将“发件人”标头添加到$ he​​aders中):

mail($to,$subject,$message,$headers,"-f ".$email);

I had the same issue with one of the servers I were dealing with. 我正在处理的其中一台服务器遇到相同的问题。 Apparently in my server, not specifying "From" header sends email from the default mail address of your account (in case of a shared hosting). 显然,在我的服务器中,未指定“发件人”标头会从您帐户的默认邮件地址发送电子邮件(如果是共享主机)。 I chose this solution as an ad-hoc fix and specified my actual from address in "Reply-To" header. 我选择此解决方案作为临时解决方案,并在“ Reply-To”标头中指定了我的实际发件人地址。 This way, I can still receive the replies sent to those email threads. 这样,我仍然可以接收发送到这些电子邮件线程的答复。

This method seems feasible for just functional email addresses (eg., support@example.com)only. 此方法仅对功能正常的电子邮件地址(例如,support @ example.com)似乎可行。 If you are using this approach for a user's email address (eg., john@example.com), chances are that the recipient might think of your email as a spam. 如果您对用户的电子邮件地址(例如john@example.com)使用此方法,则收件人很可能会将您的电子邮件视为垃圾邮件。

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

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