yet another mail problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

yet another mail problem

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I know absolutely nothing about emailers but the advice always given here is use Swift.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post 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>';
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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 . '>';
imstupid
Forum Commoner
Posts: 84
Joined: Fri Feb 18, 2005 1:24 pm

Post by imstupid »

thanks everybody. works like a charm. man it's raining hard.
Post Reply