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("username@domain.com", "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
Share on other sites

Use $_POST instead of $_REQUEST.

 

Also before you start working with variable just do:

mail('email@domain.com','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.

 

Link to comment
Share on other sites

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("username@domain.com", "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

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.