Jump to content

SMTP: Failed to set sender


scheda

Recommended Posts

I'm having a rough time getting an AS3 application working with a PHP script.

 

The PHP script takes POST variables and then sends an email using SMTP.

 

When running it through a standard HTML form, the PHP side works perfectly.

 

However, when I send the exact same POST variables through AS3 to the script, I get this error.

 

Failed to set sender: phpemailtesting@gmail.com [sMTP: Failed to write to socket: not connected (code: -1, response: )]

 

So, I'm not really sure what the issue is here... Here's some code that might help.

 

//print_r($_POST);
require_once('Mail-1.2.0/Mail.php');

$from = isset($_POST['emailfrom']) ? $_POST['emailfrom'] : '';
$to = isset($_POST['emailsubject']) ? $_POST['emailto'] : '';
$bcc = isset($_POST['bcc'])? $_POST['bcc'] : '';
$subject = isset($_POST['emailsubject']) ? $_POST['emailsubject'] : '';
$body = isset($_POST['emailbody']) ? $_POST['emailbody'] : '';
$ssl = isset($_POST['ssl']) ? $_POST['ssl'].'://' : '';
$smtp_server = isset($_POST['smtpserver']) ? $_POST['smtpserver'] : '';
$password = isset($_POST['emailpassword']) ? $_POST['emailpassword'] : '';
$port = isset($_POST['port']) ? $_POST['port'] : '';
$success_counter = 0;
$fail_counter = 0;
$bigerror;

if($from!='' && $to!='' && $subject!='' && $body!='' && $smtp_server!='' && $password!='' && $port!='') {
	if($bcc!='') {
		$bcc_array = explode(',',$bcc);
	}
	$host = $ssl . $smtp_server;
	$smtp = Mail::factory('smtp', array('host'=>$host, 'port'=>$port, 'auth'=>true, 'username'=>$from, 'password'=>$password));

	$header = array('From'=>$from, 'To'=>$to, 'Subject'=>$subject);		
	$mail = $smtp->send($to, $header, $body);

        if (PEAR::isError($mail)) {
		$bigerror = $mail->getMessage();
		$fail_counter++;
          	//echo("<p>Message failed".$to." :<br />" . $mail->getMessage() . "</p>");
        } else {
		$success_counter++;
        	//echo("<p>Message successfully sent to <b>". $to ."</b>!</p>");
        }

	for($counter=0; $counter<count($bcc_array) && $counter<=99; $counter++) {
		$header = array('From'=>$from, 'To'=>$bcc_array[$counter], 'Subject'=>$subject);		
		$mail = $smtp->send($bcc_array[$counter], $header, $body);

		if (PEAR::isError($mail)) {
			$bigerror = $mail->getMessage();
			//echo("<p>Message failed".$bcc_array[$counter]." :<br />" . $mail->getMessage() . "</p>");
			$fail_counter++;
		} else {
        	//echo("<p>Message successfully sent to <b>". $bcc_array[$counter] ."</b>!</p>");
			$success_counter++;
		}
	}
	//echo "<br /><br />Successful emails: " . $success_counter;
	//echo "<br />Failed emails: " . $fail_counter;
	echo $success_counter.",".$fail_counter.",".$bigerror;
} else {
	echo "error";
	//echo '<p>Some information is missing, please try again!</p>';
}

 

Then, the AS if anybody's interested in seeing it.

 

//Create loader to load emailer.php
var loader:URLLoader = new URLLoader();  
var request:URLRequest = new URLRequest("http://tendollartools.com/testmail/emailer.php");  

//Create POST variables
var variables:URLVariables = new URLVariables();  
variables.emailfrom = preferences["smtpLogin"];
variables.emailto = preferences["smtpLogin"];
variables.smtpserver = preferences["smtpServer"];
variables.emailpassword = preferences["smtpPassword"];
variables.ssl = preferences["smtpSSL"];
variables.port = preferences["smtpPort"];
variables.bcc = emails;
variables.emailsubject = preferences["emailSubject"];
variables.emailbody = preferences["emailBody"];

//Set method to POST and set variables as the vars to send to emailer.php
request.method = URLRequestMethod.POST;
request.data = variables;  

//Load emailer.php and run the onEmailComplete function when finished loading 
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, onEmailComplete);  
loader.load(request); 

 

The preferences object has all the correct information in it... so this is where I'm confused. Why will the exact same POST information work from an HTML form, but not when sent through AS?

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.