Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mail function is not working in PHP [duplicate]

Tags:

php

email

<?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?

like image 708
PHP CODER Avatar asked Nov 30 '13 07:11

PHP CODER


People also ask

Why is my PHP mail function not working?

Make sure the localhost mail server is configuredWithout one, PHP cannot send mail by default. You can overcome this by installing a basic mail server. For Windows you can use the free Mercury Mail. You can also use SMTP to send your emails.

Why is mail function not working?

If it's still not working: change the sender ($sender) to a local email (use the same email as used for recipient). Upload the modified php file and retry. Contact your provider if it still does not work. Tell your provider that the standard php "mail()" function returns TRUE, but not mail will be sent.

How can I send multiple emails using PHP function?

To send an email to multiple recipients in PHP, we simply separate the emails using a comma. For example, mail("[email protected], [email protected]", SUBJECT, MESSAGE); To add CC and BCC in PHP mail, we have to manually set the “Cc” and “Bcc” fields in the mail headers.


2 Answers

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);
like image 168
Bhadra Avatar answered Oct 03 '22 00:10

Bhadra


// 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

like image 24
Aman Maurya Avatar answered Oct 02 '22 23:10

Aman Maurya