Do not receive email from PHP mail () method

I tried setting up email.html and action.php so that someone could send an email from the website. Here is the code in email.html

<form action="./action.php" method="post"> <p>Your Name</p> <p><input type="text" name="name" /></p> <p>Email</p> <p><input type="text" name="email" /></p> <p>Services</p> <p><input type="text" name="service" /></p> <p>Requests</p> <p><textarea rows="8" cols="32" name="comment"></textarea></p> <p><input type="submit" value="Send" /></p> </form> 

In action.php I have

 <?php $to = " foo@outlook.com "; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = " foo2@gmail.com "; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> 

The information entered in email.html is successfully uploaded to the action.php file, but nothing was received in my Outlook inbox from the email method. Did I miss something?

+3
source share
3 answers

Start by checking the return value of mail to see if the message is being received by your SMTP server.

Also, for Namecheap documentation, your From address is not valid .

Only domains hosted on our servers can be used in the 'From' field. Any domain that is not hosted by us cannot be added to the "From" field. We had to take this measure to prevent spam sending using forums, guest books, and contact form scripts. For your site’s scripts to work correctly, you must set the From field to the email account that was created in your cPanel.

Even if it was authorized by your hosting company, you should not send mail from @ gmail.com using servers other than Gmail, in any case. It will often be blocked by SPF and other such anti-spam measures at the receiving end.

+6
source

First check the result of the mail. You should also check the php error log file.

when your mail really leaves, use a valid sender email, you can get a bounce from the receiving mail server.

Do not forget that there are many anti-spam technologies. most importantly, you respect and know how SPF works. which is one of the most unsuccessful, websites do not send emails that do not arrive at the recipient.

+1
source

OK, I hit my head hard. Just to understand that they are going to the Spam folder of my email identifier "$ to". Also check it out on your side.

0
source

Source: https://habr.com/ru/post/1240319/


All Articles