I am using the following code along with HTML for header .
$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 .
I have tried
$headers .= "From: <".$email.">\n";
and
$headers .= $email;
This displays $email in the label from header in 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.
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>";
?>
如果您使用标准邮件功能,请尝试以下操作(不要将“发件人”标头添加到$ headers中):
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. 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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.