PHP->SMTP (windows) no authentication

Associate
Joined
5 Dec 2002
Posts
141
I'm setting up a website on my windows home server, done in PHP. Website is fine, so far.
Problem i get is that one of the pages allows the user to request a new password. I'm currently with talktalk and was hoping to use the outgoing smtp.talktalk.net address to use as a relay, but it is asking for authentication that I understand the basic PHP mail function cannot deal with.
Anyone have any ideas?

The more basic the explanation the better as i've tried PEAR and run in to more problems.

Evenually the site will be off my own server but would like to try the email here first. Even if it means installing Outlook and somehow relaying through that.

Spent the last 6 hours trying all different things but still can't get it to work????:confused:
 
Associate
Joined
31 Jan 2007
Posts
1,860
I have found that if your running the site on a development server on your own pc with an application such as WAMP then the PHP mail function will not work. To solve this I followed these steps:

Sending an email from a PHP script is simple, fast and easy. If it works.
PHP mail() and SMTP Authentication
Part of what makes the PHP mail() function is so simple is its lack of flexibility. Most importantly and frustratingly, the stock mail() does not usually allow you to use the SMTP server of your choice, and it does not support SMTP authentication, required by many a mail server today, at all.

Fortunately, overcoming PHP's built-in shortcomings need not be difficult, complicated or painful either. For most email uses, the free PEAR Mail package offers all the power and flexibility needed, and it authenticates with your desired outgoing mail server, too. For enhanced security, secure SSL connections are supported.

Send Email from a PHP Script Using SMTP Authentication
To connect to an outgoing SMTP server from a PHP script using SMTP authentication and send an email:

Make sure the PEAR Mail package is installed.
Typically, in particular with PHP 4 or later, this will have already been done for you. Just give it a try.
Adapt the example below for your needs. Make sure you change the following variables at least:
from: the email address from which you want the message to be sent.
to: the recipient's email address and name.
host: your outgoing SMTP server name.
username: the SMTP user name (typically the same as the user name used to retrieve mail).
password: the password for SMTP authentication.
Sending Mail from PHP Using SMTP Authentication - Example
<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

and installed the PEAR mail module using these steps for WAMP:

Installing PEAR::Mail Class in WAMP Server 2

Go to c:\wamp\bin\php\php5.2.5\PEAR - might just be in php5.2.5

and run go-pear.bat

This will install PEAR (Confirm at cmd prompt by typing pear

Now check Go to c:\wamp\bin\php\php5.2.5\PEAR for the file Mail.php

If not available then run:

pear install --alldeps mail

at cmd prompt

Open c:\wamp\bin\apache\apache2.2.8\bin\php.ini

and find:

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Uncomment second line and change to:

include_path = ".;c:\wamp\bin\php\php5.2.5\PEAR"

Restart all services from WAMP Server 2 control panel



I hope that that will help you out.

Thanks

Regards,
Neil
 
Back
Top Bottom