Originally posted by planetsim
Sorry to say this but you cannot have a mail() in an if
I beg to differ; if mail() returns true or false there's no a priori reason why it can't be used as the test in an if statement.
But I thought about this, and reckoned I might try and find something that would work. I thought for a tick about socket connections and doing SMTP protocol by hand, but decided that someone else must've already done so; there'd have to be classes or suchlike out there already for this. So I went looking, and this is what I found. Note the caveat at the end.
Consider using the PEAR implementation of SMTP. This will allow you much better control over how you communicate with your mailserver.
This code snippet is straight from the PEAR documentation - I just added an extra comment or so.
include('Mail.php'); // I'm assuming your PEAR directories are in your
// include path
// The next five lines describe the email itself. $recipients can be an
// array of addresses, if you want.
$recipients = 'joe@example.com';
$headers['From'] = 'richard@phpguru.org';
$headers['To'] = 'joe@example.com';
$headers['Subject'] = 'Test message';
$body = 'Test message';
// The next three lines specify your server.
$params['host'] = ''; // insert your SMTP host's domain
$params['username'] = ''; // insert your username here
$params['password'] = ''; // insert your password here
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $params);
// Send the blessed thing.
$mail_object->send($recipients, $headers, $body);
I've never done this. I didn't write it. I didn't test it. Not my fault if it barfs.