How to change the FROM parameter of sending mail so that the sending server does not appear [duplicate]

0

I've used this tutorial as a base, but when I send the message via email (using PHP) it appears as sending server io.wv.pt .

Example 1:

Example2:

PHP code:

<?php
    if (isset($_POST['postsubmit'])) {
        mail($_POST['to'], $_POST['subject'] , $_POST['mensagem'], 'From: '    .$_POST['email']);
        echo 'sent';
        echo $_POST['mensagem'];
    }
?>

How do I fix this?

    
asked by anonymous 22.03.2016 / 12:13

1 answer

2

In the fourth parameter of the mail() function, set the header.

$to      = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['mensagem'];
$headers = 'From: NOME DE QUEM ENVIA <'.$_POST['email'].'>'.PHP_EOL.
'X-Mailer: PHP/'.phpversion();

mail($to, $subject, $message, $headers);

However, it depends on the SMTP server (who actually sends the email).

The SMTP server may not allow you to customize the sender's name.

    
22.03.2016 / 17:11