Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using this basic php code to send out a html email.

When i use email@email.com as a to address the script works. However, when i try to use email.2015@gmail.com the script says:

Parse error: syntax error, unexpected '@' in /home/u925912002/public_html/send_email.php on line 3

My code:

<?php

$to = ‘email.2015@gmail.com’;

$subject = 'I need to show html'; 

$from ='example@example.com'; 

$body = '<p style=color:red;>This text should be red</p>';

ini_set("sendmail_from", $from);

$headers = "From: " . $from . "
Reply-To: " . $from . "";
  $headers .= "Content-type: text/html
"; 
if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }

?>

please can someone show me what i'm doing wrong. thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
220 views
Welcome To Ask or Share your Answers For Others

1 Answer

For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working

Try this:

$headers .= "From: Your Name <$from> ";

and you can also add the 5th mail parameter:

mail($to, $subject, $body, $headers, '-finfo@userforum.com').

Works for me with these headers:

$from = "$name <$email>
";
$to = "$username <$useremail>
";
$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=utf-8' . "
";
$headers .= "From: $name <$email>
";
$headers .= "Reply-To: $name <$email>
";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...