Jump to content

Recommended Posts

I'm trying to create a mail form for the Contact Us page of my website, but the emails aren't being sent.

Here's the code I used for the mail function:

<?php
$finalmessage = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$subject.'</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
body
{
background: #000000;
font-family: Arial;
font-size: 13px;
color: #999999;
}
A:LINK     
{
color: #CCCCCC;
text-decoration: none;
}

A:VISITED  
{
color: #CCCCCC;
text-decoration: none;
}

A:ACTIVE   
{
color: #CCCCCC;
text-decoration: none;
}

A:HOVER    
{
color: #FFFFFF;
text-decoration: underline;
}  
</style>
</head>
<body>
This email was sent by '.$name.' from the WEB SPIRITED Contact Us mail form and they sent this message:<br />
'.$message.'
<p>
Their reply email address is: <a href="mailto:'.$email.'">'.$email.'</a>
</body>
</html>
';
$finalmessage = wordwrap($finalmessage, "70");

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: WEB SPIRITED <from email here>' . "\r\n";
$headers .= 'X-Mailer: PHP 5.2.5' . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";

if (mail($toemail, $subject, $finalmessage, $headers))
{
$success = "Your email has been sent.";
}
?>

 

Don't worry about the variables, because I've checked them and they're all being set correctly. The strange thing is that I have another mail script on my website that works fine so I know I can send mail, and if I put the message from that function into this one, it sends fine. If I add the message from the other script or filler text to the top of the <body> of this message it also sends fine so it's got something to do with this message.

Also, my server sends/receives it's mail through the Google mail server if that has anything to do with the problem.

Can anyone please help me? This is very frustrating.

Link to comment
https://forums.phpfreaks.com/topic/103523-strange-mail-function-problems/
Share on other sites

Hahaha, okay, fair enough. Re-read your post ... makes sense :P

 

okay ...

 

1) at the top of your script, add:

 

error_reporting(E_ALL)

 

2) Check if you get any errors, if so, paste them in

 

3) Secondly, add the following above your current mail() function ... run the script and paste the result in

 

var_dump(mail($toemail, $subject, $finalmessage, $headers));

 

Here's the results from the first error function:

Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 6

 

Notice: Undefined index: subject in /home/webspiri/public_html/webspirited/contactus.php on line 12

 

Notice: Undefined index: title in /home/webspiri/public_html/webspirited/contactus.php on line 13

 

Notice: Undefined index: lastname in /home/webspiri/public_html/webspirited/contactus.php on line 14

 

Notice: Undefined index: email in /home/webspiri/public_html/webspirited/contactus.php on line 15

 

Notice: Undefined index: message in /home/webspiri/public_html/webspirited/contactus.php on line 16

 

Notice: Undefined index: security_code in /home/webspiri/public_html/webspirited/contactus.php on line 17

 

Notice: Undefined index: submit in /home/webspiri/public_html/webspirited/contactus.php on line 20

 

Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 202

 

Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 243

 

Notice: Undefined index: loggedin in /home/webspiri/public_html/webspirited/contactus.php on line 292

 

Notice: Undefined index: level in /home/webspiri/public_html/webspirited/contactus.php on line 339

Hmmm ... well i just took your code and popped it in a script and tested it on my side ... and i get mail (even from <from email here> hahaha)

 

 

however, i do see that you're using linux but you're using \r\n in your headers ... try using only \n (\r\n is windows based newline character)

 

Also, check that $message doesn't have any unescaped ' (apostrophe's) in it ... or at least before you insert it use the addslashes() to see if it makes any difference

 

I might be talking out my ass here, because apart from those two things, i don't see any problems that could be causing this!

Unfortunately that didn't help  :( and like I said in my starting post, if I add the message from the other working mail script or filler text to the top of the <body> of this message it sends the email fine. Since my server uses the Google mail server, do you think Google could be blocking the email from arriving?

Here's the other, working, mail script:

    
<?php
            $subject = "WEB SPIRITED Email Verification and Account Activation";

            $message = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>WEB SPIRITED Email Verification and Account Activation</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<style>
body
{
font-family:Arial;
} 
</style>
</head>
<body>
This email was sent by WEB SPIRITED to verify that the email address you entered is correct and to activate your account.<br />
Please click on the link below to verify this email address and to activate your account.
<p>
<br />
<a href=\"http://www.webspirited.com/index.php?edit=activation&activationcode=$activationcode\" title=\"Verify email and activate account\">http://www.webspirited.com/index.php?edit=activation&activationcode=$activationcode</a>
<p>
<br />
If this link isn't working, copy and paste the address into the address field of your internet browser.
</body>
</html>
";
            $message = wordwrap($message, "70");

            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            $headers .= 'From: WEB SPIRITED <from email here>' . "\r\n";

            mail($email, $subject, $message, $headers);
?>

hmm ... :(

 

it could be google that's having issues with it, but i'm not sure why they would.

 

if you're developing in Windows ... i can recommend PostCast Server ... it's free, google it and download and install and set your php.ini to point to the name you specify and you have a mailserver on your local machine :) at least then you can know that your code is right without sending mail after mail. I use it, and it's saved me lots of heartache!

 

I'm sorry i can't be of more help, i just don't get it. hehe.

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.