mail () not working in PHP 5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
retrodog
Forum Newbie
Posts: 10
Joined: Sun Mar 04, 2007 12:00 am

mail () not working in PHP 5

Post 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;
	 }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Variables not existing?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
retrodog
Forum Newbie
Posts: 10
Joined: Sun Mar 04, 2007 12:00 am

Post by retrodog »

so, how do i get around this so it works? any suggestions?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
retrodog
Forum Newbie
Posts: 10
Joined: Sun Mar 04, 2007 12:00 am

Post 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.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post 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?
retrodog
Forum Newbie
Posts: 10
Joined: Sun Mar 04, 2007 12:00 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
retrodog
Forum Newbie
Posts: 10
Joined: Sun Mar 04, 2007 12:00 am

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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).
retrodog
Forum Newbie
Posts: 10
Joined: Sun Mar 04, 2007 12:00 am

Post by retrodog »

Weird, it must be the code on my other page. When I used the code that I pasted, it sent the email...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Keep an eye on it. Post back if there are any other problems.
Post Reply