send_mail() questions

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
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

send_mail() questions

Post 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!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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:
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post 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!
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post 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.



Post Reply