Jump to content

doesn't send email with gmail smtp through fsockopen()


RieqyNS13

Recommended Posts

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

 

 

 

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()

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

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?

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.....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.