Jump to content

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


RieqyNS13
Go to solution Solved by jazzman1,

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

 

 

 

Link to comment
Share on other sites

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

Edited by jazzman1
Link to comment
Share on other sites

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
Share on other sites

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?

Edited by jazzman1
Link to comment
Share on other sites

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.....
Edited by RieqyNS13
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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