Jump to content

PHP Mail Works But Inconsistent


atmega-ist

Recommended Posts

Greetings, all -

 

Curious to know if someone wouldn't mind taking a look at this code and letting me know if there are any apparent errors that may cause this problem:

 

I attempted sending the message to one of my two 1and1 email accounts and after some delay, it sent it to 1and1 account B but not 1and1 account A.  My gmail account, however, gets them every time.  I'd like to just say it's some issue with 1and1 but since it successfully got through to the one 1and1 account I'm not comfortable stopping at that.  I should also mention that for some reason, as I'm trying it today, the successful 1and1 account will no longer receive the messages...  I've tried it with directly copying the php mail code from 1and1's FAQ, though, and it seemed to work for the 1and1 account that was previously succcessful (acct B) but not acct A.

 

Very stuck...

 

Thanks

 

$from = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['question'];
mail("[email protected]", "Subject: $subject", $message, "From: $from");
echo "Mail sent";

 

1and1 FAQ with mail code:

 

http://faq.1and1.com/scripting_languages_supported/php_mail_explained/2.html

Link to comment
https://forums.phpfreaks.com/topic/213942-php-mail-works-but-inconsistent/
Share on other sites

Use $_POST instead of $_REQUEST.

 

Also before you start working with variable just do:

mail('[email protected]','Test Email','Test Body');

 

to exclude any possible error from the variables you're entering. See if that will send to your 1and1 accounts. If it does then there is a problem with your input vars.

 

Ga! Please don't use $_REQUEST, there are known security issues with this array (fine to develop with, but please not for a production server!!) I guess as you are using $_POST array?

 

//First protect yourself...
$from = strip_tags($_POST['email']);
$subject = strip_tags($_POST['subject']);
$message = strip_tags($_POST['question']);

mail("[email protected]", "Subject: ".$subject, $message, "From: ".$from);

echo "Mail sent";

 

You can't get much more stripped down than this, but it should function, it has the main ingredients, but please, use a decent tutorial to see the error of what your doing, this is open to all sorts of different methods of abuse; Spam will increase!!

 

Have a try of this one...

 

I guess the one you have chosen is the W3CSchools version, which I quite outdated at the moment, they really should update...

 

Rw

Archived

This topic is now archived and is closed to further replies.

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