Page 1 of 1

mail () not working in PHP 5

Posted: Thu Mar 08, 2007 12:25 pm
by retrodog
I have a mail script that works in PHP4 but its not sending the email in PHP5. Does anyone know why?

Code: Select all

//Form information will be emailed on this Email address.
$to = "retrodog@comcast.net";

	 $email_body = "Please contact me at the email address below. Thank you!"."\n\n";
	  $email_body .= "Name: $name"."\n";
	   $email_body .= "Email Address: $email"."\n";

	$mailheaders1  = "MIME-Version: 1.0\r\n";
	$mailheaders1 .= "Content-type: text/plain; charset=iso-8859-1\r\n";
	$mailheaders1 .= "From: Christ Church\n";
	$mailheaders1 .= "Reply-To: ecopeland@christchurch.com"; 

	$mailheaders  = "MIME-Version: 1.0\r\n";
	$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
	$mailheaders .= "From: $name \n";
	$mailheaders .= "Reply-To: $email"; 
	
//And a copy to this email address
$cc = "";

//This will be the subject of email you will recieve on form submission
$subject = "I'm interested in learning more about Christ Church Fellowship";

//--------------------------------------------------//


//A Confirmation Email will be sent automatically to the user who will submit form, 

//Write your Auto Email Subject below
$auto_subject = "Thank you for your interest in Christ Church";

//Write your Auto Email Body below
$auto_message = "As a member of Christ Church Fellowship, you will receive our regular email newsletter, Nexus, containing all the church news and updates. We will be contacting you shortly with more information. Thanks for your interest!!";
	  
		  
	if(mail($to,$subject,stripslashes($email_body),$mailheaders))  {
	     //mail($cc,$subject,$email_body,"Reply-To: $email\r\n"); 
	    mail($email,$auto_subject,$auto_message,$mailheaders1); 
	   header("Location: jump-in.php?msg=success"); 
	exit;
	}
	 else {
	  header("Location: jump-in.php?msg=issue");
	   exit;
	 }

Posted: Thu Mar 08, 2007 12:39 pm
by feyd
Variables not existing?

Posted: Thu Mar 08, 2007 12:47 pm
by Chris Corbyn
I agree with feyd, you've probably written code that expects register_globals to be on. This is now turned off by default, and the current CVS version (soon to be PHP6) has completely removed the feature.

I'm wonder why you're doing this:

Code: Select all

stripslashes($email_body)
You only created the string just above that call so it shouldnt have any additional slashes in it ;)

Posted: Thu Mar 08, 2007 1:06 pm
by retrodog
so, how do i get around this so it works? any suggestions?

Posted: Thu Mar 08, 2007 1:16 pm
by Chris Corbyn
If any of these variables come through the URL or from a form you need to use $_POST["foo"] and $_GET["foo"] rather than $foo.

http://us2.php.net/register_globals

Posted: Thu Mar 08, 2007 1:43 pm
by retrodog
All of the variables that I use for the email are defined on the page as static text except for the $name and $email which are in the body of the email content. Hmmm. I used the GET on a different page to get some of the other variables but this just seems weird. All of the email components ($to, $subject., etc) are defined on the page.

Posted: Thu Mar 08, 2007 1:55 pm
by jmut
retrodog wrote:All of the variables that I use for the email are defined on the page as static text except for the $name and $email which are in the body of the email content. Hmmm. I used the GET on a different page to get some of the other variables but this just seems weird. All of the email components ($to, $subject., etc) are defined on the page.
so you are saying only think changed is php4 to php5 and nothing else?
no server, no php.ini settings, nothing else at all...and mail() just does not work?

Posted: Thu Mar 08, 2007 2:23 pm
by retrodog
Well, the configurations may be different, but on one server its running 4.3.11 and on another 5.2.1...different hosting companies...

here are the configs of each:

http://www.brantley-janice.com/Anne/staging/test.php
http://www.christchurchlife.com/staging/test.php

Posted: Thu Mar 08, 2007 2:28 pm
by RobertGonzalez
The new machine is a windows machine running IIS6. The old is linux running Apache 1.3.37. The two systems are quite dissimilar.

Does the windows machine have a mail application installed on it to send mail out?

Posted: Thu Mar 08, 2007 2:40 pm
by retrodog
Well, the person I was in touch with at the new hosting company said that they had a php script that worked for sending out an email but then said that there was an ASP mail component that could be used if i wanted to use that...

Posted: Thu Mar 08, 2007 2:47 pm
by RobertGonzalez
Good luck telling PHP to talk to ASP.

Find out from the host what the mailing application is for you to be able to send emails from the PHP application. They should be able to tell you that and all the specifics you need to send mails. Unless it is Godaddy, in which case you may want to look for a different host (or switch to the Linux accounts instead of Windows).

Posted: Thu Mar 08, 2007 3:02 pm
by retrodog
Weird, it must be the code on my other page. When I used the code that I pasted, it sent the email...

Posted: Thu Mar 08, 2007 3:38 pm
by RobertGonzalez
Keep an eye on it. Post back if there are any other problems.