Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMTP Mail() problem

Status
Not open for further replies.

craigglenn

Technical User
Oct 30, 2003
42
US
NEW TO PHP

I am having a problem sending an notification email once a form is submitted on my Wordpress blog hosted on GoDaddy. Just a simple contact form.

In the beginning I was getting my email delivered but it was very slow, 15 mins to and hour and not it just never shows up.

I have tried various code settings but here is where I am now. I don't get it delivered, but based on test scripts I found here It says the message is being handed over to the MTA without errors.

Here is my code...

$to = "test1@yahoo.com";
$subject = "New Comment on domain1.com";
$message = "From: ".$_name."\n"."eMail: ".$_email."\n".$_comment;

$headers = 'From: test2@domain1.com' . "\n" .
'Reply-To: test2@domain1.com'. "\n" . 'X-Mailer: PHP/';

mail($to,$subject,$message,$headers);

Sorry if I left any important details out, please let me know if you need additional information. Thanks for your help.

Craig




"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
UPDATE

My test message (simple) finally went through.

this is the code I used to test with.

$myAddress = 'email@domain.com'; //replace with working adddress
mail($myAddress, 'subject', 'this is a test message', "From: $myAddress\r\n") or die ('error in mail function');
echo 'mail delivered to MTA ok';

It took about 45 minutes to deliver. Test using my code listed in first post still have not gone through.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
It seems then to be a server issue, and not PHP. If the mail function is successfully handing over the email to be sent, then PHP is doing what its supposed to. At that point PHP's involvement ends.

Perhaps talking to the Godaddy people about their mail server would be beneficial.

Other than that, you could try to use PHPMailer class instead. It has its own smtp so it doesn't need to use Godaddy's server.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Godaddy's servers have some issues with sending off properly without valid headers being sent.

Here is what my headers are, which send off an email everytime someone fills out a profile (sales lead)

Code:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <" . $_SESSION['web_email'] . ">" . "\r\n";
			"Reply-To: " . $_SESSION['web_email'] . "" . "\r\n" .

My suggestion is to set them email as a HTML email, and send it off that way, none of my 129 sites have problems sending emails to my email account.



Code:
<?php

$to = "test1@yahoo.com";
$subject = "New Comment on domain1.com";

$message = 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Domain</title>
</head>
<body>
<table>
	<tr>
		<td>From:</td>
		<td>$_name</td>
	</tr>
	<tr>
		<td>Email:</td>
		<td>$_email</td>
	</tr>
	<tr>
		<td>Comments:</td>
		<td>$_comment</td>
	</tr>
</table>
</body>
</html>
'

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <test2@domain1.com>" . "\r\n";
			"Reply-To: test2@domain1.com" . "\r\n" .

mail($to,$subject,$message,$headers);

See how that works for you.

Beware of hackers bearing executables. Happy Hunting. 'irc.2600.net'
 
Thanks so much for your detailed answer. I really believe this is going to solve my problem but I am getting this error and can't seem to put my finger on the parse error.

Parse error: syntax error, unexpected T_VARIABLE in /home/content/74/6837474/html/domain1/insert_contact.php on line 59

Line 59 is the </html>' area... no wait now I see it... missing ;

testing now... fingers crossed... I will let you know the result.

thanks again

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
the code is missing a semicolon after the single quote.

 
Well I waited overnight and never received the email to test1@yahoo.com. I was so certain that we had it.

I changed to a different $to email as someone had suggested and just sent it out. I will wait an hour and see.

Here is the response I received from GoDaddy. Of course they didn't share their test code... that might have been helpful.

***********godaddy********************
Our support staff has responded to your request, details of which are described below:

Discussion Notes
Support Staff Response
Dear Sir/Madam,

Thank you for contacting Hosting Support regarding your domain2.com account. We have reviewed the issue of not receiving all the emails being sent from your php mail() scripts. I sent myself 15 emails using a test script and confirmed that i received all 15 emails over 30 minutes after running script. If you are still not receiving all emails after allowing time for the emails to be received we recommend trying a different recipient email address to see if this resolves your issue as we have confirmed all emails are being sent correctly from the server. Please let us know if we can help you in any other way.

Sincerely,
Brandon H
Hosting Support
************END GoDaddy***************

Looking forward to something else to try. Is there anything else I could provide? php.ini files, my form code? complete PHP code?


"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
OK, UPDATE...

I changed the $To address from my yahoo email to one of my GoDaddy emails and it went through but I lost the post data from some reason. I know the data went through to the table so it's there... Maybe "" '' issue? here is what I received in the message.

From: $_name
Email: $_email
Comments: $_comment


Thanks again for all your help.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
That was my mistake. You lost the post data because I am apparently an invalid. This will work without a problem for you.

Code:
<?php

$to = "test1@yahoo.com";
$subject = "New Comment on domain1.com";

$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Domain</title>
</head>
<body>
<table>
	<tr>
		<td>From:</td>
		<td>', $_name,'</td>
	</tr>
	<tr>
		<td>Email:</td>
		<td>', $_email,'</td>
	</tr>
	<tr>
		<td>Comments:</td>
		<td>', $_comment,'</td>
	</tr>
</table>
</body>
</html>';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <test2@domain1.com>" . "\r\n";
			"Reply-To: test2@domain1.com" . "\r\n" .

mail($to, $subject, $message, $headers);

Beware of hackers bearing executables. Happy Hunting. 'irc.2600.net'
 
I get a parse error on this line.

<td>', $_name,'</td>

unexpected ,

I am testing with ""...
did not get parse error but waiting to see if data passes or just the $_vars again...


Thanks so much for hanging with me and helping me out. Been working on this for 4 days now.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Variables don't get expanded inside single quotes. Which is why yu weren;t getting the post data. And the concatenation operator is the period . not the comma , S you get the parser errors.

I'd use the heredoc syntax instead to to avoid quoting issues. But for a straight fix:

Try this instead:

Code:
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Domain</title>
</head>
<body>
<table>
    <tr>
        <td>From:</td>
        <td>'[COLOR=yellow red].[/color] $_name [COLOR=yellow red].[/color]'</td>
    </tr>
    <tr>
        <td>Email:</td>
        <td>'[COLOR=yellow red].[/color] $_email [COLOR=yellow red].[/color]'</td>
    </tr>
    <tr>
        <td>Comments:</td>
        <td>'[COLOR=yellow red].[/color] $_comment [COLOR=yellow red].[/color]'</td>
    </tr>
</table>
</body>
</html>';



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Try -

Code:
<?php

$to = "test1@yahoo.com";
$subject = "New Comment on domain1.com";

$message = '
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">[/URL]
<html xmlns=\"[URL unfurl="true"]http://www.w3.org/1999/xhtml\">[/URL]
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Domain</title>
</head>
<body>
<table>
	<tr>
		<td>From:</td>
		<td>$_name</td>
	</tr>
	<tr>
		<td>Email:</td>
		<td>$_email</td>
	</tr>
	<tr>
		<td>Comments:</td>
	<td>$_comment</td>
	</tr>
</table>
</body>
</html>';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <test2@domain1.com>" . "\r\n";
			"Reply-To: test2@domain1.com" . "\r\n" .

mail($to,$subject,$message,$headers);

Beware of hackers bearing executables. Happy Hunting. 'irc.2600.net'
 
And may I also suggest abandoning the mail() command and instead using phpmailer with its smtp class. You will find it significantly easier and more useful in debugging.
 
I looked into using phpmailer but have not found a good resource document for getting through the whole process. Would love to hear some suggestion as I am not getting this to work and don't understand why.

vacunita: I do understand where you were going with the . for concat and single quotes but it hasn't worked for me. Perhaps I have not waited long enough for the smtp process.

If I use without ' . $var . ' it goes through pretty quick but with no data just the $var.

chunkII123: I can't see what you changed in your last post but I will copy it and give it a try as well. why would this work without any ' . $ . ' ? but I am desperate and will try anything at this point.

Looks like I will have to learn phpmailer... and start over.

I do have to repeat this entire process on other sites and want to do it the best way possible.



"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
vacunita: I do understand where you were going with the . for concat and single quotes but it hasn't worked for me. Perhaps I have not waited long enough for the smtp process.

You are mixing symptoms here and its making it difficult to follow.

If you want the data from the variables to go into the message you need to concatenate them outside of the string, like I set above because the variables will not get replaced when they are inside single quotes. That's just the way it is.

Now, the variables should have no bearing on how the email is being sent.






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks to vacunita and chunkII123: for your patience and expertise. The reason it got confusing at the end was that I had a typo in my email address and the email was not going through again. From all the coping and pasting and changing to my data. sorry for that.

Thank you both so much and I have learned a lot!


THIS WORKS!

$to = "toname@todomain.com";
$subject = "New Comment on MySite";

$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Domain</title>
</head>
<body>
<table>
<tr>
<td>From:</td>
<td>' . $_name . '</td>
</tr>
<tr>
<td>Email:</td>
<td>' . $_email . '</td>
</tr>
<tr>
<td>Comments:</td>
<td>' . $_comment . '</td>
</tr>
</table>
</body>
</html>';

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <name@domain.com>" . "\r\n";
"Reply-To: name@domain.com" . "\r\n" .

mail($to, $subject, $message, $headers);

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
If you use the double quotepost, the one i sent last, you don't have to use the singles-quote/ period one your have (' . *var* . '), instead you can just use "<html>....>$_name<....</html>"; it allows you to use the variable within the code, without extra steps.

However, is you use the double-quote type, it would require you to cancel all the double quotes throughout with a "\"

Like -

Code:
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">[/URL]

Good job getting it to work!

Beware of hackers bearing executables. Happy Hunting. 'irc.2600.net'
 
a 3rd alternative for the strings is to use herdoc format (one of jpadies posts first made me aware of this)
it enables you tou use variables & quotes without the need to escape things
Code:
echo <<<end
variable1 ="$var"
end;


I do not Have A.D.D. im just easily, Hey look a Squirrel!
 
I looked into using phpmailer but have not found a good resource document for getting through the whole process. Would love to hear some suggestion as I am not getting this to work and don't understand why.

the phpmailer package, when downloaded, has loads of good examples.

there is also a phpmailer-fe which is a form-to-email class
 
thanks again everyone. I will look into phpmailer.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top