Hello, I wrote a script to send out an email and it works except for the subject line. Not sure why. Anyone know? Is it the "" marks?

$to = ($_POST['e_mail']);
if (!isset($_POST['e_mail']))
  
  $subject = "Registration at MySite.com"; 
    $message = "Welcome to MySite!
				Your user account has been created. Just login at MySite.com to complete your web page, 
				or if already complete login to manage your personal account.
				Enjoy!
     
    Thank You  
     
    This is an automated response, please do not reply."; 
     
    mail($to, $subject, $message, "From: MySite\n 
  X-Mailer: PHP/" . phpversion());
Member Avatar for diafol

Use braces about if/else conditions:

$to = ($_POST['e_mail']);
if (!isset($_POST['e_mail'])){
 $subject = "Registration at MySite.com"; 
 $message = "Welcome to MySite! Your user account has been created. Just login at MySite.com to complete your web page, or if already complete login to manage your personal account. Enjoy! 
     Thank You  
     This is an automated response, please do not reply."; 
 mail($to, $subject, $message, "From: MySite\nX-Mailer: PHP/" . phpversion());
}

Thanks ardav. OK I should of noticed that but the email actually still worked it was just the subject line that did not work at all (No subject) and the From line reads MySite X_Mailer:PHP/5.2.1.
$message and $to to worked fine.

Member Avatar for diafol
if (isset($_POST['e_mail'])){

Perhaps that? I thin k the reason it worked (kinda) before was because of this:

if (!isset($_POST['e_mail']))
 
  $subject = "Registration at MySite.com";

That was the same as doing:

if(!isset($_POST['e_mail']))$subject = "Registration at MySite.com";

WHich means subject will not be set if $_POST is not set. Everything else will be though.

commented: Awsome +2

OK, I see it now. Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.