php - SMTP with Auth doesnt work -
i trying send emails, php script, reason, not receiving emails.
$to = email; $nameto = "who to"; $from = sec email; $namefrom = "who from"; $subject = "hello world again!"; $message = "world, hello!"; authsendemail($from, $namefrom, $to, $nameto, $subject, $message); function authsendemail($from, $namefrom, $to, $nameto, $subject, $message) { $smtpserver = smtp server $port = "25"; $timeout = "30"; $username = sec email; $password = password $localhost = smtp server $newline = "\r\n"; $smtpconnect = fsockopen($smtpserver, $port, $errno, $errstr, $timeout); $smtpresponse = fgets($smtpconnect, 515); if(empty($smtpconnect)) { $output = "failed connect: $smtpresponse"; homecoming $output; } else { $logarray['connection'] = "connected: $smtpresponse"; } fputs($smtpconnect,"auth login" . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['authrequest'] = "$smtpresponse"; fputs($smtpconnect, base64_encode($username) . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['authusername'] = "$smtpresponse"; fputs($smtpconnect, base64_encode($password) . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['authpassword'] = "$smtpresponse"; //fputs($smtpconnect, "ehlo $localhost" . $newline); fputs($smtpconnect, "ehlo" . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['heloresponse'] = "$smtpresponse"; fputs($smtpconnect, "mail from: $from" . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['mailfromresponse'] = "$smtpresponse"; fputs($smtpconnect, "rcpt to: $to" . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['mailtoresponse'] = "$smtpresponse"; fputs($smtpconnect, "data" . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['data1response'] = "$smtpresponse"; $headers = "mime-version: 1.0" . $newline; $headers .= "content-type: text/html; charset=iso-8859-1" . $newline; $headers .= "to: $nameto <$to>" . $newline; $headers .= "from: $namefrom <$from>" . $newline; fputs($smtpconnect, "to: $to\nfrom: $from\nsubject: $subject\n$headers\n\n$message\n.\n"); $smtpresponse = fgets($smtpconnect, 515); $logarray['data2response'] = "$smtpresponse"; fputs($smtpconnect,"quit" . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['quitresponse'] = "$smtpresponse";
and getting this:
array(10) { ["connection"]=> string(84) "connected: 220-vm01.masterd.pt esmtp exim 4.84 #2 thu, 13 nov 2014 10:29:17 -0500 " ["authrequest"]=> string(75) "220-we not authorize utilize of scheme transport unsolicited, " ["authusername"]=> string(25) "220 and/or mass e-mail. " ["authpassword"]=> string(43) "503 auth command used when not advertised " ["heloresponse"]=> string(26) "500 unrecognized command " ["mailfromresponse"]=> string(26) "500 unrecognized command " ["mailtoresponse"]=> string(43) "250-vm01.masterd.pt hello [109.71.45.39] " ["data1response"]=> string(19) "250-size 52428800 " ["data2response"]=> string(14) "250-8bitmime " ["quitresponse"]=> string(16) "250-pipelining " }but email never come inbox!
i had same issue, until made next changes:
the "ehlo $localhost" command should sent before "auth login"
the username should sent on same line "auth login", i.e.:
fputs($smtpconnect,"auth login" . base64_encode($username) . $newline); $smtpresponse = fgets($smtpconnect, 515); $logarray['authrequest'] = "$smtpresponse";
it helped lot troubleshoot when printed out $smptresponse each time echo function. responses need fgets response several times because response has multiple lines.
php smtp
No comments:
Post a Comment