from header?

focus

Member
Messages
128
Reaction score
0
Points
16
I'm having trouble with the from header in the below mail script. Can anyone help?

PHP:
function is_valid_email($from_email)
{
    return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si', $from_email);
} 


$headers  =  "From: " . $_POST["name"];
$headers .= "<" . $_POST["email"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";

$headers .=     "MIME-Version: 1.0\r\n"
      . "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
    . "Content-Transfer-Encoding: 7bit\r\n"; 


$to_email = "dada@hotmail.com";
$subject = "Watch Website Thing";
$name.=$_POST['name']."\n" ;
$from_email.=$_POST['email'] ."\n" ;
$msg.=$_POST['message']."\n" ;


$message = "

<body>

    <b>Name:</b><br>
    $name

<br> <br>

    <b>Email:</b><br>
    $from_email

<br> <br>

    <b>Message:</b><br>
    $msg

</body>
";
    
    
$sent = mail($to_email, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully."; }

else
{print "We encountered an error sending your mail"; }

?>
 

dlukin

New Member
Messages
427
Reaction score
25
Points
0
PHP:
$sent = mail($to_email, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully."; }

else
{print "We encountered an error sending your mail"; }


print "\$_POST['email'] is " . $_POST["email"] 
print "<code>$headers</code>";


?>

Add the last two lines to see what the actual values are.
...you might have to look at the return source since you put from address in < brackets >
 
Last edited:

focus

Member
Messages
128
Reaction score
0
Points
16
the
PHP:
print "<code>$headers</code>";
bit did not work but when that is removed it displays Your mail was sent successfully.$_POST['email'] is focus@hotmail.com
 

Qombat

New Member
Messages
25
Reaction score
1
Points
0
Any particular reason why your from headers are in "<" and ">"?
 

focus

Member
Messages
128
Reaction score
0
Points
16
No reason jus tryin to figure it out following different tutorials but i cant seem to :((
 

focus

Member
Messages
128
Reaction score
0
Points
16
I got it working abit better but i can only get it working to display the email its from when the email is sent. I would like it to display the name and then when the user presses reply it replies to their email. (I hope that made sense)

My code at the moment:

PHP:
$headers .= 	"MIME-Version: 1.0\r\n"
  	. "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
	. "Content-Transfer-Encoding: 7bit\r\n"; 


$to_email = "daaaa@hotmail.com";
$subject = "Watch Fair";
$name.=$_POST['name']."\n" ;
$from_email.=$_POST['email'] ."\n" ;

$headers .= "From: $from_email\r\n";

	
$msg .=$_POST['message']."\n" ;


	
$message = "

<body>

    <b>Name:</b><br>
    $name

<br> <br>

    <b>Email:</b><br>
    $from_email

<br> <br>

    <b>Message:</b><br>
    $msg

</body>
";


	
$sent = mail($to_email, $subject, $message, $headers) ;
 
Top