EASY email script question - how to specify mail server?

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
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

EASY email script question - how to specify mail server?

Post by forzato »

Hello:

I'm a newbie using a very simple script (half dozen lines of code) on my web site server to handle a form. A user's 'name' and 'email' are sent to the script, then script sends email to user... like an autoresponder.

The script uses the php 'mail' function.

My script works great EXCEPT if 'email' is out of my web site domain... then it doesn't work at all.

My server host tells me to "change the script so that the mail server is either localhost or 2k3mail.siteprotect.com" They tell me that my script is currently using smtp.mydomain.com as mail server...

I have not explicitly stated the mail server in my script.

I don't know how to do this with php... do you?

PS: It's a windows server with php installed and I have the php info file and php code if needed.

Thank you for any ideas...
User avatar
SystemWisdom
Forum Commoner
Posts: 69
Joined: Sat Mar 26, 2005 5:54 pm
Location: A Canadian South of the 49th Parallel

Post by SystemWisdom »

You could try:

Code: Select all

ini_set( 'SMTP','localhost' );

// or

ini_set( 'SMTP','2k3mail.siteprotect.com' );
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

SystemWisdom,

You're name is underestimating your skill... You're advise worked!

I'm so happy I can't tell you!

PS: I don't know if it matters... I had to first use mail, then use your ini_set then use mail again. If I don't use the second mail after the ini_set then it won't mail my Bcc to an email in my domain. (?)

ie: mail(abc)
ini_set (xyz)
mail (abc)
NOT
ini_set (xyz)
mail (abc)

PPS: This is a shared serevr if it matters (?)
User avatar
SystemWisdom
Forum Commoner
Posts: 69
Joined: Sat Mar 26, 2005 5:54 pm
Location: A Canadian South of the 49th Parallel

Post by SystemWisdom »

Hmm, sounds strange, are you using localhost??

Maybe post your Mail Header string?

I am on a shared host as well, but I dont recall ever having that problem..
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

Thanks for staying with me...
SystemWisdom wrote:Hmm, sounds strange, are you using localhost??

Code: Select all

ini_set( 'SMTP','2k3mail.siteprotect.com' );
works, but...

Code: Select all

ini_set( 'SMTP','localhost' );
does not (if that's your quesion)

Here's the modified code (the variables 'email' and 'name' are sent to this script via POST from a Flash swf):

Code: Select all

<?php
$myredirect = "http://www.corporatecar.com/";
$email = $_POST["email"];
$myname = "Corporate Car";
$mymail = "CustomerService@CorporateCar.com";
$subject = "***** Yada Yada ******";
$body = $_POST["name"] . ", here is yada yada...
Thanks for the help... much appreciated"; 
$headers = "Content-Type: text/plain; charset=us-ascii\nFrom: $myname <$mymail>\nBcc:<$mymail>\nReply-To: <$mymail>\nReturn-Path: <$mymail>\nX-Mailer: PHP";
ini_set( 'SMTP','2k3mail.siteprotect.com' );
mail($email,$subject,$body,$headers); 
?>

PS: It's not that important, but for diagnostic purposes... With our fix in place I get an 'undeliverable' notice from Postfix, even though the mails deliver as expected.
forzato
Forum Newbie
Posts: 22
Joined: Sat Mar 19, 2005 5:49 pm

Post by forzato »

forzato wrote: I had to first use mail, then use your ini_set then use mail again. If I don't use the second mail after the ini_set then it won't mail my Bcc to an email in my domain. (?)
ie: mail(abc)
ini_set (xyz)
mail (abc)
NOT
ini_set (xyz)
mail (abc)
...is from my lack of complete testing and an error on my part - sorry about that.
User avatar
SystemWisdom
Forum Commoner
Posts: 69
Joined: Sat Mar 26, 2005 5:54 pm
Location: A Canadian South of the 49th Parallel

Post by SystemWisdom »

Sorry, makes no sense to me, if the mail routine can send one mail, then there should be no reason for it failing on the second one (in ur bcc).

I hope you figure it out!
Post Reply