0

I created a contact form and want it to mail it to my e-mail. But when I try to use it nothing happens.

I've tried a demo e-mail code and that worked so I guess it's not a server problem.

The code:

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
    { 
        $name=$_REQUEST['name']; 
        $email=$_REQUEST['email']; 
        $phone=$_REQUEST['phone']; 
        $message=$_REQUEST['message']; 

        if (($name=="")||($email=="")||($phone=="")||($message=="")) 
        { 
            $error = true;   
        } 
        else
        {         
            $from="From: $name<$email><$phone>\r\nReturn-path: $email"; 
            $subject="Contact"; 
            mail("foo@hotmail.com", $subject, $message, $from); 
            $complete = true;
        } 
    }   
?> 

PS: $complete will become true.

C.Ronaldo
  • 593
  • 1
  • 6
  • 25
  • 2
    `mail()` does no works on local server, if you want to use it on local then change your smtp address in php.ini – Manjeet Barnala May 20 '16 at 11:59
  • 1
    Have you checked the spam folder? Most emails sent from PHP's built in `mail` function end up there. You're better of setting up a mail server and using `PHPMailer` – dimlucas May 20 '16 at 12:00
  • Hi, I have uploaded it online. So it's not local @dimlucas Yup, I've checked the spam folder – C.Ronaldo May 20 '16 at 12:01
  • Take a look into the http servers error log file. That is where you can simply _read_ what the issue is instead of having to _guess_. – arkascha May 20 '16 at 12:01
  • To debug remove `$complete = true;` and use `$complete = mail("foo@hotmail.com", $subject, $message, $from);` instead. `mail()` will return true on successful mail relaying and false in case of any error. – maxhb May 20 '16 at 12:06
  • @maxhb $complete will become true too with your code. – C.Ronaldo May 20 '16 at 12:11
  • If $complete becomes true than php has done everything it can do. You'll have to debug your mail server. Check logs for further information. A very detailed guide to debug your problems is included in this post: http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail – maxhb May 20 '16 at 12:19

0 Answers0