Jump to content

Mail not sending via mail()


PadLock

Recommended Posts

Problem Background:

 

The PHP code I am working with spans three pages. It starts on the first gathering information in a form. On the second it checks to make sure all fields were entered and that the data inside them is valid. On this second page these values are set to cookies and we are taken to a third page if there are no errors where the information is mailed to my client.

 

The third page is where I am having my problems.


Problem:

 

Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/31/9395831/html/PHP/Z4L_Snd.php on line 36

 

 

Line 36 consists of

mail($to, $subject, $message, $headers);

 

This is the code for the third page which is getting the error in its entirety.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php



$td = date("Y-m-d");
$today =   "Date             :" . $td;
$fname =   "\n" . "First Name       : " . $_COOKIE["fName"] . "\n";
$lname =   "Last Name        : " . $_COOKIE["lName"] . "\n";
$email =   "Email            : " . $_COOKIE["email"] . "\n";
$hphone =  "Home Phone       : " . $_COOKIE["Hphone"] . "\n";
$mphone =  "Mobile Phone     : " . $_COOKIE["Mphone"] . "\n";
$contact = "Preferred Contact: " . $_COOKIE["contact"] . "\n";

$to = "client email address";
$subject = "Contact Information: " . $fname . " " . $lname;
$message = $today . $fname . $lname . $email . $hphone . $mphone . $contact;

	   
$from = "client info email address is here";
$headers = "From:" . $from;
mail($to, $subject, $message, $headers); 
echo "Mail Sent.";
?>



</body>
</html>

 

Any ideas?

Link to comment
Share on other sites

I take it that $to and $from are actual emails address? e.g $to = "mail@example.com";

 

If so, try running a telnet to see if you can actually send an email

 

Yes they are actual emails. The site is hosted on GoDaddy and the original form I made that just sends the email without checking for errors works so I know that emails can in fact be sent which is what puzzles me about this. I should also add that the $from email that is going in $headers is of the same domain as the website so that shouldn't be the issue either.

Link to comment
Share on other sites

if it sent before when you wasn't checking for errors, then the problems resides outside of the mail function, surely?

 

try

echo "mail($to, $subject, $message, $headers)";

 

That will show you how the 'mail' looks when you are sending it, see if they are any errors.

You can also try

 

mail("add_the_email_here", "this is a test", "this is a test message, did you receive this?", "from: me@email.com");

 

I also found this :http://drupal.org/node/196792

which blames goDaddy for the same problems, so maybe its with goDaddy?

 

/insidus

Link to comment
Share on other sites

I fixed the problem. It seems that defining the subject or the body of the email with the variables above which consisted of other predefined variables from the cookies was the problem.

 

The original mail() code was:

mail($to, $subject, $message, $headers); 

 

What I wound up doing was:

mail($to, "New Contact Information", $today.$fname.$lname.$email.$hphone.$mphone.$contact, $headers); 

 

This seems to be working. I'm not sure if it is because I am getting the variable definitions from cookies or what the issue was but this seemed to fix it. If anyone happens to know exactly what caused the issue I would love to know so I can work around it more intelligently in the future.

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.