SMTP send email with Gmail
SMTP send email with Gmail
(OP)
thread434-1521422: PHPMAILER
May I ask your help, my notebook computer as server with XP window, do I need other software to send email, by setting
the php.ini smtp=local host smtp port = 25. After running pgm,
I have the follwing
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
Here is my program . . .
<?php
include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Host = "ssl://smtp.gmail.com::465";
$mail->SMTPSecure = "ssl";
$mail->IsSMTP(); // send via SMTP
//IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "c238@gmail.com"; // SMTP username
$mail->Password = "my_password"; // SMTP password
$webmaster_email = "c238@gmail.com"; //Reply to this email ID
$email="c238@gmail.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
May I ask your help, my notebook computer as server with XP window, do I need other software to send email, by setting
the php.ini smtp=local host smtp port = 25. After running pgm,
I have the follwing
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
Here is my program . . .
<?php
include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Host = "ssl://smtp.gmail.com::465";
$mail->SMTPSecure = "ssl";
$mail->IsSMTP(); // send via SMTP
//IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "c238@gmail.com"; // SMTP username
$mail->Password = "my_password"; // SMTP password
$webmaster_email = "c238@gmail.com"; //Reply to this email ID
$email="c238@gmail.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
RE: SMTP send email with Gmail
CODE
to
CODE
$mail->Port = 465;
$mail->SMTPSecure = 'tls'; //or try 'ssl'
and make sure your phpmailer is up to date
RE: SMTP send email with Gmail
it takes a long time to run (about 90 sec.) I do NOT see the echo
message "mail error" or "message has been sent", no Error info.
I check my Gmail account, no messages.
Can you teach me to put a trace to the script, so as to know how
the execution is going, if there is a loop running. How do I know the phpmailer is up to date? Thanks again
RE: SMTP send email with Gmail
try turning on display_errors and setting error_reporting to E_ALL in php.ini. You cannot set these in the script if you want to capture syntax errors.
remember to restart the webserver after making changes to php.ini
RE: SMTP send email with Gmail
the display_errors is on, error_reporting to E_ALL, to restart
the webserver by running Apache Restart. I simplify my script.
<?php
include("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "c238@gmail.com"; // SMTP username
$mail->Password = "my_passw"; // SMTP password
$mail->From = "c238@gmail.com";
$mail->FromName = "Webtester";
$mail->AddAddress("p238@yahoo.com", "Mike");
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi, This is the HTML BODY "; //HTML Body
echo " aaa2 test2 ";
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
exit;
if(!$mail->Send()){echo "Mailer Error: " . $mail->ErrorInfo;} else {echo "Message sent";}
?>
Testig result is the same as before, it execute with no parse errors or warning. It takes long time (about 90 sec). I put an exit before the if (...),it take 2 sec to run. No email sent,
no messages, I check my gmail acct, nothing. Thanks . . .
RE: SMTP send email with Gmail
CODE
function logger($message){
echo '<pre>';
if(is_object($message)):
$message = get_object_vars($message);
endif;
if(is_array($message)):
print_r($message);
else:
echo $message;
endif;
echo '<pre>';
}
require "phpmailer/class.phpmailer.php";
logger('retrieved mailer class');
$mail = new PHPMailer();
logger('instantiated php mailer');
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
$mail->IsSMTP(); // send via SMTP
logger('set phpmailer to SMTP');
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "c238@gmail.com"; // SMTP username
$mail->Password = "my_passw"; // SMTP password
$mail->From = "c238@gmail.com";
$mail->FromName = "Webtester";
$mail->AddAddress("p238@yahoo.com", "Mike");
logger('added address to mail object');
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
logger('about to send message');
if(!$mail->Send()):
logger("Error sending mail \n" . $mail->ErrorInfo);
logger("trying alternative port");
$mail->Port = 587;
if(!$mail->Send()):
logger("Error sending mail with alternative port \n" . $mail->ErrorInfo);
else:
logger('Successfully sent mail via alternative port');
endif;
else:
logger('successfully sent email');
endif;
?>
RE: SMTP send email with Gmail
I can see the first 5 logger messages, but not the ones after
the if(!$mail->Send()):
The run time is long, about 70 sec. I put an exit before the if(!$mail->Send(), it takes 2 sec, I checked my gmail and yahoo acct no mail send/received.
Thank you very much.
RE: SMTP send email with Gmail
CODE
Run the code and then please paste back the log output.
Please also let us know what os you are running ( and version ).
RE: SMTP send email with Gmail
web server V.2.2.4, PHP script language V.5.2.1, MYSQL database V.5.0.27
By the way do I need to install the software for openSSL? Thanks
RE: SMTP send email with Gmail
The fact that you are not receiving any error message is troubling. Do check the error console for windoze and also the error logs for php (for location check php.ini)
RE: SMTP send email with Gmail
[mail function]
; For Win32 only.
SMTP = smtp.netvigator.com
smtp_port = 25
; For Win32 only.
sendmail_from = c238@gmail.com
;extension=php_mbstring.dll
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_msql.dll
extension=php_mysql.dll
;extension=php_oci8.dll
extension=php_openssl.dll
;extension=php_oracle.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_pdo.dll
;extension=php_pdo_sqlite.dll
;extension=php_winbinder.dll
RE: SMTP send email with Gmail
i assume you have checked that there are no firewall apps installed?
what errors are in the php logs? please copy and paste them here.
can you confirm that you are using the latest copy of phpmailer?
also check with your ISP that they allow outbound smtp connections to anything other than their servers (many do not)
the issue feels like a timeout caused by your isp just failing the packets deliberately. in this circumstance the socket never gets a response so just carries on going. windows does not support socket_set_timeout so no fix there. effectively you are waiting for the webserver to give up.
try this code
CODE
ini_set('display_errors', true);
error_reporting(E_ALL);
function logger($message){
echo '<pre>';
if(is_object($message)):
$message = get_object_vars($message);
endif;
if(is_array($message)):
print_r($message);
else:
echo $message;
endif;
echo '<pre>';
}
require_once "phpmailer/class.phpmailer.php";
logger('retrieved mailer class');
$mail = new PHPMailer();
logger('instantiated php mailer');
$mail->IsSMTP(); // send via SMTP
$mail->SMTPDebug = 5;
logger('set phpmailer to SMTP');
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "c238@gmail.com"; // SMTP username
$mail->Password = "my_passw"; // SMTP password
$mail->From = "c238@gmail.com";
$mail->FromName = "Webtester";
$mail->AddAddress("p238@yahoo.com", "Mike");
logger('added address to mail object');
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
logger('about to send message');
try{
$mail->Send();
logger('mail sent successfully over tls');
} catch ( phpmailerException $e ) {
logger("Error sending mail \n" . $e->errormessage());
logger("trying alternative port");
try{
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->send();
logger('Mail sent successfully via alternative port');
} catch (phpmailerException $e ){
logger("Error sending mail with alternative port \n" . $e->errorMessage());
} catch (Exception $e) {
logger( $e->getMessage());
}
} catch (Exception $e) {
logger( $e->getMessage());
}
?>
RE: SMTP send email with Gmail
I run the above code, I have these . . .
retrieved mailer classinstantiated php mailerset phpmailer to SMTPadded address to mail objectabout to send messageSMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 mx.google.com ESMTP x2sm1528025pbn.13
"
SMTP -> get_lines(): $data is "220 mx.google.com ESMTP x2sm1528025pbn.13
"
SMTP -> FROM SERVER:220 mx.google.com ESMTP x2sm1528025pbn.13
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-mx.google.com at your service, [218.102.107.200]
"
SMTP -> get_lines(): $data is "250-mx.google.com at your service, [218.102.107.200]
"
SMTP -> get_lines(): $data was "250-mx.google.com at your service, [218.102.107.200]
"
SMTP -> get_lines(): $str is "250-SIZE 35882577
"
SMTP -> get_lines(): $data is "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
"
SMTP -> get_lines(): $data was "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
"
SMTP -> get_lines(): $str is "250-8BITMIME
"
SMTP -> get_lines(): $data is "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
250-8BITMIME
"
SMTP -> get_lines(): $data was "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
250-8BITMIME
"
SMTP -> get_lines(): $str is "250-STARTTLS
"
SMTP -> get_lines(): $data is "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
"
SMTP -> get_lines(): $data was "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
"
SMTP -> get_lines(): $str is "250 ENHANCEDSTATUSCODES
"
SMTP -> get_lines(): $data is "250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
"
SMTP -> FROM SERVER: 250-mx.google.com at your service, [218.102.107.200]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS
"
SMTP -> get_lines(): $data is "220 2.0.0 Ready to start TLS
"
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\AppServ\www\phptest2\testing2\phpmailer\class.smtp.php on line 199
RE: SMTP send email with Gmail
RE: SMTP send email with Gmail
download the latest version from sourceforge.
latest version is 5.1
RE: SMTP send email with Gmail
I do a search on my hard drive, looking for files of "php_openssl.dll, I find 2 locations,
(1)C:\Documents and Settings\Venus\my documents\appserv\Php5\ext
(2)C:\AppServ\Php5\ext
Now about the version of phpmailer, I have it a month ago, I think I got version 5.1, as seen from copy
/*~ class.phpmailer.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Version: 5.1 |
| Contact: via sourceforge.net support pages
RE: SMTP send email with Gmail
RE: SMTP send email with Gmail
I find 2 locations of php_openssl.dll (as my last message (1)/(2)
in 2 Appserv folders, should I delete (1)?
Any problem with my phpmailer? thanks
RE: SMTP send email with Gmail
the php manual can be found here: http://fr2.php.net/openssl
there is no requirement to edit openssl.dll or anything. just follow the instructions
RE: SMTP send email with Gmail
To install the openssl, I go to fr2.php.net/openssl . .
then I go to
http://so
Description Download Size Last change Md5sum
‧ Complete package, except sources Setup 4658384 4 December 2008 9d9e1c90bb4976a554f604e9e69ac0a0
I just do the above setup using the wiz. step by step, but
‧ Sources Setup
‧ Binaries Zip
‧ Developer files Zip
‧ Documentation Zip
‧ Sources Zip
‧ Original source h
those 6 items I do not touch. . .
How to make sure that the dll is accessible to php and windows?
After Setup, the openssl file was in C:\program files\Gnuwin32,
just 2 pdf files, no exe files. I need your advice, thanks . .
RE: SMTP send email with Gmail
You need to work out which php instance you are using. Whether it is via appserv (whatever that is) or native php. Since I have no idea what appserv is I can boy recommend doing the normal thing and installing apache mysql and php separately and manually (ie not using the automated installers) . I have never had any problems that route.
The only gotcha for windows is ensuring that certain dlls are available in the windows path environment variable. The link for this is http:
Essentially you can either edit the path variable or just copy the dll to windows/system32. The former is better from a tidiness perspective.