I've struggled with getting mail functionality set up so am asking for some help. I decided I would use Pear-mail as described at http://www.phpmaniac.net/wiki/index.php/Pear_Mail. So I installed the pear packages mail, Net-SMTP and mail-mime.
C:\Users\user name>pear list
INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
PACKAGE VERSION STATE
Archive_Tar 1.3.2 stable
Console_Getopt 1.2.3 stable
Mail 1.1.14 stable
Mail_Mime 1.5.2 stable
Mail_mimeDecode 1.5.0 stable
Net_SMTP 1.3.1 stable
Net_Socket 1.0.8 stable
PEAR 1.6.1 stable
Structures_Graph 1.0.2 stable
I'm trying to send the mail using my gmail account which works just fine with outlook for my personal mail. When I run the code below, what I see in the browser is a message in the bottom left of the screen saying "waiting for localhost" that lasts about one minute followed the line of echo messages below which I inserted for debugging purposes
c:\wamp\bin\php\php5.2.5\PEARinclude mail doneinclude mime doneSTARTStart sending
The email send never seems to get a response to echo out the results and from then on I don't get any indication of what happened. Seems like I am missing something. The mail id and password are set to the real values not what is shown below. Thanks for any assistance
The code is
<?php
set_include_path('c:\wamp\bin\php\php5.2.5\PEAR');
echo get_include_path();
include('Mail.php');
echo "include mail done";
include('Mail/mime.php');
echo "include mime done";
// Constructing the email
echo "START";
$sender = "nbt9p54@gmail.com"; // Your email address
$recipient = "nbt9p54@yahoo.com"; // The Recipients name and email address
$subject = "Test Email"; // Subject for the email
$text = 'This is a text message.'; // Text version of the email
$html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Add an attachment
$file = "Hello World!";
$file_name = "Hello text.txt";
$content_type = "text/plain";
$mime->addAttachment ($file, $content_type, $file_name, 0);
// Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP authentication params
$smtp_params["host"] = "smtp.gmail.com";
$smtp_params["port"] = "587";
$smtp_params["auth"] = true;
$smtp_params["username"] = "my-id@gmail.com";
$smtp_params["password"] = "my-password";
echo "Start sending";
// Sending the email using smtp
$mail =& Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
echo "End sending";
if($result === 1)
{
echo("Your message has been sent!");
}
else {
echo("Your message was not sent: " . $result);
}
?>