How to mail in PHP

Hi,

I want to create a forgotten password page, where the user enters in their email address, the script queries the database for that email address, creates a unique ID, stores that unique ID in the database, then emails the unique ID and the User ID off to the user in an HTML link e.g. http://somesite.com/reset-password.php?userId=2&uniqueId=132832189312978312. The reset page would then match the unique ID to the one in the database and let them enter in a new password into the form.

Ok so I can do most of that so far except from the emailing to the user. I’m running an Ubuntu Server 10 at the moment as my test server which is on my local network. I have set up a generic sendmail service on port 25 on my server but I’d like to do testing with external SMTP servers as well because when the site is running in the hosted live environment as it will likely use their mail servers.

I’ve had a play round with the PHP mail() function but it won’t send anything at the moment for some reason. I’ve been playing with the PEAR mail sending functionality on this example:
http://www.blog.highub.com/javascript/javascript-core/make-ubuntu-php-localhost-mail-function-work/

It actually sends the email and I can get it in my gmail but I get about 50 lines of errors saying:
[php]Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/mimePart.php on line 307

Strict Standards: Non-static method Mail_mimePart::encodeHeader() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/mime.php on line 1316

Strict Standards: Non-static method Mail_mimePart::_explodeQuotedString() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/mimePart.php on line 827

Strict Standards: Non-static method Mail::factory() should not be called statically in /opt/lampp/htdocs/site/sendmail.php on line 28[/php]

Any idea on how to get this working? Also do many web hosts have PEAR configured on them? I’m a bit dubious about relying on it if most web hosts don’t actually run it.

Many thanks!

If mail() function is not working, you may need to check sendmail_path settings in your php.ini
Also sometime having \r\n in the message headers might cause problem, and in this case this need to be replaced with just \n For more info see: Sendmail tutorial

Thanks. I ended up using Zend for emailing in the end.

Forget about using PEAR for email until they fix the strict error messages. Seems to be broken at the moment. You can always turn the error messages off with ini_set(‘display_errors’, ‘0’); but that’s probably not the best solution.

The Zend mail functionality is very good and not too hard to figure out.
http://zendframework.com/manual/en/zend.mail.html

Are you sure you’re using mail() correctly?

It’s to, subject, then message.

For each line in the message, don’t use more than 70 characters. To start a new line I believe it’s backslash () n (so it’s \n)

I heard the 70 character thing in w3schools.com

Sponsor our Newsletter | Privacy Policy | Terms of Service