RieqyNS13 Posted May 16, 2013 Share Posted May 16, 2013 When I try send email with PHPMailer_v5.1, it works. But when I try make it self, I know that the result is possible to error or email not sent. My problem is the email not sent. this my code: <?php $fp = fsockopen("ssl://smtp.gmail.com", 465, $errNo, $errStr, 15); if(!$fp){ echo "not connected"; }else{ fputs($fp, "EHLO"."\r\n"); fputs($fp, "AUTH LOGIN"."\r\n"); fputs($fp, base64_encode("author@gmail.com")."\r\n"); fputs($fp, base64_encode("password")."\r\n"); fputs($fp, "MAIL FROM:<author@gmail.com>"."\r\n"); fputs($fp, "RCPT TO:<target@gmail.com>"."\r\n"); fputs($fp, "DATA"."\r\n"); fputs($fp, "Subject: This is subject"."\r\n"); fputs($fp, "This is body message"."\r\n"); fputs($fp, "."."\r\n"); fputs($fp, "QUIT"."\r\n"); fclose($fp); } ?> And I have enable extension=php_openssl.dll in php.ini Link to comment https://forums.phpfreaks.com/topic/278064-doesnt-send-email-with-gmail-smtp-through-fsockopen/ Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 You have to concatenate your string, something like: <?php $fp = fsockopen("ssl://smtp.gmail.com", 465, $errNo, $errStr, 15); $str = fputs($fp, "EHLO"."\r\n"); $str .= fputs($fp, "AUTH LOGIN"."\r\n"); $str .= fputs($fp, base64_encode("author@gmail.com")."\r\n"); $str .= etc...... echo fputs($fp,$str); fclose($fp); Or.....much better, create the string and pass it as a second parameter to fputs() Link to comment https://forums.phpfreaks.com/topic/278064-doesnt-send-email-with-gmail-smtp-through-fsockopen/#findComment-1430465 Share on other sites More sharing options...
RieqyNS13 Posted May 16, 2013 Author Share Posted May 16, 2013 I've tried your solution, but the email still not sent here : <?php $fp = fsockopen("ssl://smtp.gmail.com", 465, $errNo, $errStr, 15); if(!$fp){ echo "not connected"; }else{ $str = fputs($fp, "EHLO"."\r\n")."\n"; $str .= fputs($fp, "STARTTLS"."\r\n")."\n"; $str .= fputs($fp, "AUTH LOGIN"."\r\n"); $str .= fputs($fp, base64_encode("author@gmail.com")."\r\n")."\n"; $str .= fputs($fp, base64_encode("password")."\r\n")."\n"; $str .= fputs($fp, "MAIL FROM:<author@gmail.com>"."\r\n")."\n"; $str .= fputs($fp, "RCPT TO:<target@gmail.com>"."\r\n")."\n"; $str .= fputs($fp, "DATA"."\r\n")."\n"; $str .= fputs($fp, "Subject: This is subject"."\r\n")."\n"; $str .= fputs($fp, "This is body message"."\r\n")."\n"; $str .= fputs($fp, "."."\r\n")."\n"; $str .= fputs($fp, "QUIT"."\r\n")."\n"; echo fputs($fp, $str); fclose($fp); } ?> and I have checked the spam folder, but it empty Link to comment https://forums.phpfreaks.com/topic/278064-doesnt-send-email-with-gmail-smtp-through-fsockopen/#findComment-1430477 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 Turn on error_reporting and try something like that: $fp = fsockopen("ssl://smtp.gmail.com", 465, $errNo, $errStr, 15); $str = "EHLO \r\n AUTH LOGIN \r\n "; $str .= base64_encode("author@gmail.com")."\r\n"; $str .= base64_encode("password")."\r\n"; $str .= "etc......"; fputs($fp,$str); fclose($fp); Are you sure that your email header format is correct, too? Link to comment https://forums.phpfreaks.com/topic/278064-doesnt-send-email-with-gmail-smtp-through-fsockopen/#findComment-1430480 Share on other sites More sharing options...
RieqyNS13 Posted May 16, 2013 Author Share Posted May 16, 2013 thanks for your reply. but last minute I've add delay after every fputs() execution, and it works so, the code like this: $fp = fsockopen("ssl://smtp.gmail.com", 465, $errNo, $errStr, 15); if(!$fp){ echo "not connected"; }else{ fputs($fp, "EHLO"."\r\n"); Sleep(2); fputs($fp, "AUTH LOGIN"."\r\n"); Sleep(2); fputs($fp, base64_encode("target@gmail.com")."\r\n"); Sleep(2); etc..... Link to comment https://forums.phpfreaks.com/topic/278064-doesnt-send-email-with-gmail-smtp-through-fsockopen/#findComment-1430481 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 He-he, I was completely forgot about that I'm using openssl on my RedHat server but in Bash language. Good job Link to comment https://forums.phpfreaks.com/topic/278064-doesnt-send-email-with-gmail-smtp-through-fsockopen/#findComment-1430482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.