cancel
Showing results for 
Search instead for 
Did you mean: 

[ccgi] using PHP mail() with domains

BJepson
Grafter
Posts: 34
Registered: ‎15-08-2007

[ccgi] using PHP mail() with domains

Hi,
I have two domains hosted on the ccgi server and I would like to generate emails fromphp that have the appropriate From address.
I have tried several variations on the headers field in the mail function but the email always somes from some "Force9 user<jepson@ptn-ccgi01.plus.net>".
Is there any way to get it to use a valid from address?
3 REPLIES 3
jah
Grafter
Posts: 43
Thanks: 2
Registered: ‎09-06-2007

Re: [ccgi] using PHP mail() with domains

Try this little script to test:
<?php
ini_set("SMTP","smtp.force9.net");
ini_set("smtp_port","25");
define("RCPT_EMAIL", "addressee@foo.com");
define("SNDR_EMAIL", "you@yourdomain.com");
define("EMAIL_SUBJECT", "TESTING");
$message = "It worked!";
mail(RCPT_EMAIL, EMAIL_SUBJECT, $message, "From: ".SNDR_EMAIL);
?>
Mail sent :)

[tt]smtp.force9.net[/tt] is just an example (and probably doesn't work) so use the force9 smtp server that you use at home.
The fourth paramater to mail() [tt]"From: you@yourdomain"[/tt] should be the key to your success.  Hopefully.
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: [ccgi] using PHP mail() with domains

I always do this using the optional additional_parameters argument (see http://uk.php.net/manual/en/function.mail.php)
e.g.:

<?php
$to = 'someone@example.com';
$from = 'someoneelse@example.com';
$subject = 'Test mail';
$headers = "From: $from";
$message = 'Test, please ignore';
mail  ($to, $subject, $message, $headers, "-f $from");
?>
BJepson
Grafter
Posts: 34
Registered: ‎15-08-2007

Re: [ccgi] using PHP mail() with domains

Thanks to you both.
I tried that, or at least I tried to try that yesterday but it wouldn't work.  Your script worked first time.  Great.