Page 1 of 1

Mail() Problem

Posted: Sat Dec 27, 2003 2:23 am
by lokhanglee
I am writing a PHP program to get visitors' feedback:

<?php

$name = $_POST["name"] + "\n";
$email = $_POST["email"] + "\n";
$tel = $_POST["tel"] + "\n";
$msg = $_POST["msg"] + "\n";

$to = "evan@stjudechurch.org.hk";
$from = $_POST["name"];
$from_email_address = $_POST["email"];
$subject = "Message";
$body = $_POST["msg"];

if(mail($to, $subject, $body, $from))
printf("OK");
else
printf("Failed");
?>

However, it fails. What is wrong?

Posted: Sat Dec 27, 2003 2:28 am
by Weirdan
fourth param to mail is actually `headers`. So try :
mail($to,$subject,$body,"From: $from <$from_email_address>")

Posted: Sat Dec 27, 2003 5:09 am
by lokhanglee
Now it seems that it is OK. However, I cannot get the E-mail when I try to send myself an E-mail.

hmm

Posted: Sun Dec 28, 2003 3:00 am
by mwong
I tried it on my own. I replaced the $_POST with strings so I didn't have to make my own form....it seemed to work perfectly fine. Maybe you have something else on the page that is hindering your code..

Code: Select all

<?php 

$name = $_POST&#1111;"name"] + "\n"; 
$email = $_POST&#1111;"email"] + "\n"; 
$tel = $_POST&#1111;"tel"] + "\n"; 
$msg = $_POST&#1111;"msg"] + "\n"; 

$to = "wongdesign2k1@yahoo.com"; 
$from = "wongdesign2k1@yahoo.com"; 
$from_email_address = "wongdesign2k1@yahoo.com"; 
$subject = "This is the subject"; 
$body = "This is the body"; 

if(mail($to, $subject, $body, $from)) 
printf("OK"); 
else 
printf("Failed"); 
?>