Jump to content

simple, but can't figure out whats wrong


acidglitter

Recommended Posts

I'm trying to get a contact page to work, and this is the code I'm using, but its not reaching my email for some reason.. Does anyone see whats wrong with this?

 

$name=$_POST['name']; $email=$_POST['email']; $comment=$_POST['comment'];

$to="[email protected]";
$subject="NEW message from";
$headers="From: $name";
$now=date("M d, Y");
$message="$comment

----------------------------
From: $name
Sent: $now";
mail($to,$subject,$message,$headers);

Link to comment
https://forums.phpfreaks.com/topic/57033-simple-but-cant-figure-out-whats-wrong/
Share on other sites

Are you sure your server is set up right? If you are using shared hosting, then you might call your host and ask about sending mail from php. In one instance, I had to use this code to make sending mail possible:

ini_set("SMTP","mail.mysite.com"); // this being my server's SMTP outgoing server
// yours could be smtp.yourdomain.com
ini_set("smtp_port","25"); // you might have a different port number for SMTP

Two suggestions:

 

#1 - avoid using 'free' email addresses since they routinely dump email with less than perfect and complete headers

 

#2 - check the php manual to see what headers you need to use.  Yours is woefully short of what's needed.

Try this code

$name=$_POST['name']; $email=$_POST['email']; $comment=$_POST['comment'];

 

$to="[email protected]";

$subject="NEW message from";

$headers="From: $name";

$now=date("M d, Y");

$message="$comment

 

----------------------------

From: $name

Sent: $now";

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

if($ok==1)

{

echo"message sucessfully send";

}else{

echo"Error!Try again";

}

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.