9
<?php if (isset($_POST['submit'])) { //if "email" is filled out, proceed $name= mysql_real_escape_string($_POST['name']); $phone= mysql_real_escape_string($_POST['phone']); $to = "[email protected]"; $subject = "Customer Intrested"; $message = "Buyer Information and Intrested in land."; $message.= "Customer Name :".$name."\n"; $message.= "Customer Phone :".$phone."\n"; $mail=mail($to, "Subject: $subject",$message ); if($mail){ echo "success"; } else { echo "failed."; } ?> 

I am using the above code to send email..but i am unable to get the result..it always showing the "Thank you message"..

I can able to get the values of name and phone.

How to fix this Problem?

11
  • where are you run this code offline or online? Commented Nov 30, 2013 at 7:23
  • if you have set mail setting in php.ini, check your junk mails Commented Nov 30, 2013 at 7:23
  • @renishkhunt i am running this code on online Commented Nov 30, 2013 at 7:25
  • @HarishSingh I checked the span folder also..but not getting the mail Commented Nov 30, 2013 at 7:26
  • @PHPCoder your email function working. Commented Nov 30, 2013 at 7:45

2 Answers 2

13
mail($to, "Subject: $subject",$message ); echo "Thank you for using our mail form"; 

instead of this ,first check if the mail is sent

$mail=mail($to, "Subject: $subject",$message ); if($mail){ echo "Thank you for using our mail form"; }else{ echo "Mail sending failed."; } 

By this actually u can know whether your mail function in working or not

if it is not working.the problem can be with SMTP settings in your localhost

enable errors in php if not enabled using

ini_set('display_errors',1); 
Sign up to request clarification or add additional context in comments.

2 Comments

if i am using if($mail)condition it shows the mail sending failed..How to correct it?
but it shows success in localhost
2
// message lines should not exceed 70 characters (PHP rule), so wrap it $message = wordwrap($message, 70); 

for more help:http://www.w3schools.com/php/php_mail.asp

1 Comment

I'd recommend never using w3schools

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.