Page 1 of 1

send_mail() questions

Posted: Thu Apr 21, 2005 10:17 pm
by Phoenixheart
Maybe some stupid questions but these are messing me. All know there's a send_mai() in php and say it's easy to use. But I can't find any documentation that explains FROM WHICH EMAIL ADDRESS the mail will be sent.
Say I have 3 email addresses (boss@any.com, sales@any.com and me@any.com), how do I know (or decide) which one to send a mail?
And how to test mail functions on localhost? When we install PHP using the binary package, they have us provide a email address, say to be used (me@localhost.com)
These are some codes I took from a site, anyone can explain them?

Code: Select all

<?
function send_mail($to, $from, $subject, $body) {// is $from the address php wil use to send?
$path_to_sendmail = "/usr/sbin/sendmail";// for what? a CGI to send mail?
$fp = popen("$path_to_sendmail -t", "w");
$num = fputs($fp, "To: $to\n");
$num += fputs($fp, "From: $from\n");
$num += fputs($fp, "Subject: $subject\n\n");
$num += fputs($fp, "$body");
pclose($fp); if ($num>0) { return 1; } else { return 0; } }
?>
8O
Thanks for any help!

Posted: Fri Apr 22, 2005 1:30 am
by Chris Corbyn
Yes.... the mail() function does this.

$path_to_sendmail is for unix systems which use a mail path.

$from is the email address to send the email from (it jujst creates the correct header). The rest speks for itself.

Look at that link I sent you above. The PHP mail() function is easy to use and would be more flexible anyway :wink:

Posted: Sat Apr 23, 2005 3:44 am
by Phoenixheart
Yeah I found it out.
But we can only set the sendmail_from and sendmail_path if we are the server administrator.
Is there a way to over-ride those varibles? Use ini_set()?
Thanks for your help!

Posted: Sat Apr 23, 2005 6:20 am
by crazytopu
Q1. I can't find any documentation that explains FROM WHICH EMAIL ADDRESS the mail will be sent. Say I have 3 email addresses (boss@any.com, sales@any.com and me@any.com), how do I know (or decide) which one to send a mail?

A: well, you can use whatever email address you want. In you php.ini file, search for SMTP, and there insert your ISP's SMTP

Code: Select all

&#1111;mail function]
; For Win32 only.
SMTP = your ISP's SMTP

; For Win32 only.
;sendmail_from = me@example.com
Remember, a semicolon means that line is gonna be ignored. So, take off the semicolon whereever necessary.

Q2:And how to test mail functions on localhost?

if you want to check if the mail function is working you have to have a net connection, also you need to know your ISP's SMTP. Without a net connection and appropriate SMTP configuration (just explained above how to do that) you cant test mail function on localhost. Oh, yah, if you have your own mail server set up on your localhost, then it's probably a different story.


Q: When we install PHP using the binary package, they have us provide a email address, say to be used (me@localhost.com)

A: this address has nothing to do with mail() funciton.


Finally, search a bit hard, there are plenty of explanation you will find.