Help - Search - Members - Calendar
Full Version: Php Mail Script Needed
TotalChoice Hosting Family Forums > TotalChoice Hosting General Support > Security Discussions
wayne
I have been told by the help desk that my php script which sends out an email receipt is no longer allowed on my server. It was a basic command in the form to
mail($recipient,$subject,$body,$from)

The reason is that it is sending out mail as nobody which is no longer allowed.

I have many many php pages that use this script to send out receipts to customers. Is there a way to use php to send mail and not have it send it a "nobody". I do put a reply address in the $from variable but obviously that is not what is needed.


Thanks in advanced.
TCH-Bruce
Use the -f switch to tell sendmail to set the envelope address:

-f email@address.com
wayne
Thanks

I have found this reference to the -f switch

<?php
mail('nobody@example.com', 'the subject', 'the message', null,
'-fwebmaster@example.com');
?>

Not sure what the null is. Do I leave this as null? What I want is an email sent out to my customer and to bcc myself.
Would this work?

<?php
mail('customer@example.com', '$subject', '$message', null,
'-fmyaddress@****');
?>

Not sure how I would get this to bcc me as well or can I do this?
TCH-Bruce
CODE
mail($contactemail, $subject, $message, $headers, "-f".$myemail);
TCH-Andy
Hi Wayne,

The null that you have should really be the headers;

Try;

CODE
$fromname = "me";
$fromemail = "me@here.com";

$toname = "you";
$toemail = "you@there.com";

$subject = "subject of email";

$message = "Test message\n";
$message .= "\n";
$message .= "signed\n";

$headers = "From: $fromname <$fromemail>\r\n";
$headers .= "Reply-To: $fromname <$fromemail>\r\n";
$headers .= "To: $toname <$toemail>\r\n";
$headers .= "bcc: $fromname <$fromemail>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: My script Mailer\n";

mail($toemail, $subject, $message, $headers, "-f".$fromemail);


You do need to check that any variables you use that allow people to enter values into (ie, from a web page) are checked to ensure they only contain a single email address though - otherwise it quickly becomes very insecure.
wayne
Thanks for the speedy responses.
I will edit my scripts and yes I check the email addresses.


Wayne
wayne
I am having 2 problems. One of which I have fixed.

This is what I have"

$fromname = "wayne";
$fromemail = "wayne@here.com";

$toname = "customer";
$toemail = "customer@there.com";

$subject = "subject of email";

$message = "Test message\n";
$message .= "\n";
$message .= "signed\n";

$headers = "From: $fromname <$fromemail>\r\n";
$headers .= "Reply-To: $fromname <$fromemail>\r\n";
$headers .= "To: $toname <$toemail>\r\n";
$headers .= "bcc: $fromname <$fromemail>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: My script Mailer\n";

mail($toemail, $subject, $message, $headers, "-f".$fromemail);


I have noticed 2 problems when I run the script as instructed above.


The $toemail address is getting 2 emails. So I removed the $headers entry for the "To" field and now it is fixed (since the $toemail is also in the actual mail() command).


HOWEVER I get the mail to $toname bouncing back. This email address is working as it is on my day job email address (on a server not located at TCH if that means anything). I do get the mail at the bcc address (which is an acount on the TCH server running the script).

The error in the bounced mail is
unrouteable mail domain "there.com"

Any help is much appreciated.


Wayne
TCH-Andy
without the real domain name it's difficult to investigate.

Although we don't provide coding support via the help desk, open a ticket and we'll take a quick look at why it's failing to that domain.
wayne
actually it is any domain that is outside my server. ie I have tried hotmail.com, yahoo.ca and all fail

Seems that if I make the address my own domain, I get the mail fine.
TCH-Bruce
I have no idea why you are getting errors Wayne. I copied and pasted your script into a test PHP file changed the email addresses to my own and it worked perfectly.
wayne
Bruce

I opened a help desk ticket and they fixed something on the server end. All is now working with the -f switch.

Thanks all for your advice, as usual service here at TCH ROCKS!!
TCH-Bruce
Glad it's working. thumbup1.gif
TCH-Rob
Alright Wayne, nice to see you are on the road again.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.