Hi there,
I have a fairly simple question. I have a registration form on my site and I want to send the new user a confirmation email so that I can confirm they agree to my terms etc. I am using mail() and for the most part it works just fine. But, every once in a while, either the mail won't come to me or I'll get a duplicate message from several days before.

I'm just wondering if using mail() is the best way to go for this purpose or if I need to use something like phpmailer or other classes out there.

I'm not clear on if mail() uses smtp or not and what the pros and cons are of the different ways of sending an email via php. Anyone have any insight?

Thank you so much,

Johnny

Hi there,
PHP's mail() function should work just fine for what you're doing as I've used it many times for the exact same thing with no problems.

For alternatives, the only 2 I know of are PEAR's mail function which (obviously) requires the PEAR libraries on your web server. For more documentation go to pear.php.net . The other alternative is directly opening a connection to your smtp server using php's socket functions, for more info on that go to http://www.php.net and search for 'socket'. But both of these ways are far more complex than just using mail() (which does run on smtp btw).

The only reason I can think of it failing occasionally would be something to do with your mail server, not the code.

Hi,
You may go to the following link where you can get a massive information about "How to Send Email from a PHP Script Using SMTP Authentication".

http://email.about.com/od/emailprogrammingtips/qt/et073006.htm

If you find some valuable work, do add it to my reputation. Thankyou

hi iam newts thread
i tried ur advice but iam not sure where i can find the mail.php file that is displayed in the code of the link u have given out

I'm just wondering if using mail() is the best way to go for this purpose or if I need to use something like phpmailer or other classes out there.

Well the mail() function is for sure one of the easiest ways to go unless you have a corrupted mail server. Have you tried placing the mail function inside an if statement to see if it passes all of the time. Perhaps your mail server is sometimes a bit busy and doesn't get a chance to process the message. I would suggest doing something like the following:

if (!mail($to,$title,$message)) {
if (!mail($to,$title,$message)) {
mysql_query('INSERT INTO `later_email_processing` SET `to`="'.
mysql_real_escape_string($to).'", `title`="'.
mysql_real_escape_string($title).'", `message`="'.
mysql_real_escape_string($message).'"') or die('Mail Storage error<br>'.mysql_error());
}
}

Then set a crone job so that once an hour all messages in the database are processed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.