Forum Moderators: coopster

Message Too Old, No Replies

Question about the mail function

         

Jakotsu

1:34 am on Apr 8, 2007 (gmt 0)

10+ Year Member



Hi,
I'm using the mail function to send an email, but it does not use the "from" address that I specify in the last parameter, instead it uses the address set on php.ini... is there a way to specify my own address, that is, overriding the address set in PHP.INI?

Any help is greatly appreciated.

eelixduppy

3:32 am on Apr 8, 2007 (gmt 0)



You could use ini_set to change the value, since sendmail_from is php_ini_all:

[url=http://www.php.net/ini-set]ini_set[/url]("sendmail_from","you@example.com");

Jakotsu

11:18 pm on Apr 8, 2007 (gmt 0)

10+ Year Member



Well, for some reason that function does not work... notice that I don't own the server, I only have an account in there with limited space and bandwidth.

eelixduppy

11:20 pm on Apr 8, 2007 (gmt 0)



You should not need to own the server for that function to work. That is, unless your host disabled that function (might want to check with your host). Are you getting any errors?

dublinmike

2:12 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



Some configurations require the email address you are sending from to actually exist as a mailbox in your account (rightly so!), i.e. if you have just 1 address setup in your account me@mydomain.com and try to send from info@mydomain.com using the mail function, it can reject it on the grounds that info@mydomain.com doesn't exist...

jatar_k

2:15 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try setting all headers

$headers .= "From: some company <$email>\n";
$headers .= "Return-Path: $email\n";
$headers .= "Reply-To: $email\n";

I have had some issues with this in the past and can't remember whoch one of the above fixed it but one of them should

Jakotsu

4:52 am on Apr 10, 2007 (gmt 0)

10+ Year Member



Thanks! Indeed I had to set the headers this way:

<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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

Thanks again.