M
M
macintosh872014-10-11 02:04:11
PHP
macintosh87, 2014-10-11 02:04:11

How to correctly configure the sending of mail messages from the server?

On two different free servers I use the same php code to send data from the contact form:

<meta http-equiv='refresh' content='3; url=http://xxx.com/'>
<meta charset="utf-8">
<?php
if (isset($_POST['name'])) {$name = $_POST['name']; if ($name == '') {unset($name);}}
if (isset($_POST['phone'])) {$phone = $_POST['phone']; if ($phone == '') {unset($phone);}}
 
if (isset($name) && isset($phone)){
 
$address = "[email protected]";
$mes = "Имя: $name \n Телефон: $phone";
$send = mail ($address,$mes,"Content-type:text/plain; charset = UTF-8\r\nFrom:$name");
if ($send == 'true')
{echo "Сообщение отправлено, через 3 секунд Вы будете направлены на главную страницу, где сможете продолжить чтение <a href='http://xxx.com/'>xxx</a>";}
else {echo "Ошибка, сообщение не отправлено!";}
 
}
else
{
echo "Вы заполнили не все поля, необходимо вернуться назад!";
}
?>

From one server, messages come to the specified mailing address, but not from the other. Why is that?
Please also tell me if this code is correct.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-10-11
@macintosh87

if postfix is ​​not configured on the server, nothing will come. Or it will go to spam as a letter sent from an untrusted server. If you want reliability, look for an SMTP provider.
And yes, use ready-made solutions, ala swiftmailer. Always use something ready-made for mail. There will be fewer problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question