Mail() Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lokhanglee
Forum Newbie
Posts: 2
Joined: Sat Dec 27, 2003 2:23 am

Mail() Problem

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

fourth param to mail is actually `headers`. So try :
mail($to,$subject,$body,"From: $from <$from_email_address>")
lokhanglee
Forum Newbie
Posts: 2
Joined: Sat Dec 27, 2003 2:23 am

Post 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.
mwong
Forum Commoner
Posts: 34
Joined: Sun Dec 28, 2003 2:58 am

hmm

Post 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"); 
?>
Post Reply