Page 1 of 1

yet another mail problem

Posted: Mon Aug 28, 2006 10:00 am
by imstupid
hey everybody-
I have a typical "cannont send an email using php' problem.

I have a bunch of fileds in flash, and they are posting to an external php page which is not sending the mail. thI originally tried using sendmail, however the host won't allow sendmail. I then used their suggested script and of course it doesn't work.

I'm using loadVariableNum in actionscript which works fine since I can add variables from this particular server to a database, but there is something wrong with the script they provided.

Can somebody please check out this code and point me in the right direction?

Code: Select all

<?PHP

	
	$yourname = $_POST['yourname'];
	$friendsname = $_POST['friendsname'];
  	$email = $_POST['email'];
  	$friendsemail = $_POST['friendsemail'];
  	$themessage = $_POST['message'];
	

	
	include('Mail.php');

	$recipients             = '"friendsemail" <$friendsemail>';
	$headers['From']        = '"yourname" <$email>';
	$headers['To']          = '"friendsemail" <$friendsemail>';
	$headers['Cc']          = '';
	$headers['Bcc']         = '';
	$headers['Subject']     = 'test php message subject';
	$body                   = '$themessage';
	$params['host']         = 'scriptmail.intermedia.net';

	$mail_object    =& Mail::factory('smtp', $params);

	if ( $mail_object->send($recipients, $headers, $body) ) {
        echo "Mail was successfully sent";
	}
	else {
        echo "Cannot send mail!";
	}
	
?>
Thats how they provided it, I added in the varible names of course.

thanks a million.

Posted: Mon Aug 28, 2006 10:03 am
by Ollie Saunders
I know absolutely nothing about emailers but the advice always given here is use Swift.

Posted: Mon Aug 28, 2006 11:02 am
by Chris Corbyn
That code doesn't tell us much. Again, I can recommend you use Swift Mailer to connect to SMTP, or just use it as a smart interface to the mail() function if you don't want SMTP.

Posted: Mon Aug 28, 2006 11:42 am
by imstupid
yeah, aparently, this line:

Code: Select all

$headers['From']        = '"yourname" <$email>';
had to be an actual email address on that particular server with the same domain. so, that script they provided works now, however I can't get any of the variables to load in. for instance, if someone provides an email address, I can't seem to figure out how to add that into :

Code: Select all

$headers['To']          = '"friendsemail" <$friendsemail>';

Posted: Mon Aug 28, 2006 11:50 am
by RobertGonzalez
Your problem is that you are wrapping PHP vars in literal single quotes. This...

Code: Select all

$headers['From']        = '"yourname" <$email>';
... should be ...

Code: Select all

$headers['From']        = '"yourname" <' . $email . '>';

Posted: Mon Aug 28, 2006 12:14 pm
by imstupid
thanks everybody. works like a charm. man it's raining hard.