Mail () ... Doubt


I have an contact form that uses the php command mail()…
I’ts all working now, after a little bit of working, but there is one thing that i can’t change…

When anyone fills the form and send it to the desired contact, it keeps coming with the same from address:

Is there any way of change it ?! It does’nt need to be everytime changeable. But i just don’t want it to be:

Hope you can help… :wink:

CyA ! …


Have you read Dreamhost’s Wiki entry on php mail() function?

Specifically the “Advanced example”:

$to = "";
$subject = “Nonsensical Latin”;

// compose headers
$headers = “From:\r\n”;
$headers .= “Reply-To:\r\n”;
$headers .= “X-Mailer: PHP/”.phpversion();

// compose message
$message = “Lorem ipsum dolor sit amet, consectetuer adipiscing elit.”;
$message .= " Nam iaculis pede ac quam. Etiam placerat suscipit nulla.";
$message .= " Maecenas id mauris eget tortor facilisis egestas.";
$message .= " Praesent ac augue sed enim aliquam auctor. Ut dignissim ultricies est.";
$message .= " Pellentesque convallis tempor tortor. Nullam nec purus.";
$message = wordwrap($message, 70);

// send email
mail($to, $subject, $message, $headers);
More specifically, the “From” part of the header. That should fix your problems.


web design, development & seo by DigitalVibe


I’ve tried this too… But it still don’t work… The Emails keep coming as

If you want to see the code page i’ll post it here…

Tnks for the help…

Sendemail Script <?php $contato = $_POST['contato']; $nome = $_POST['nome']; $tel = $_POST['tel']; $cel = $_POST['cel']; $estado = $_POST['estado']; $cidade = $_POST['cidade']; $mailfrom = $_POST['mailfrom']; $dados = $_POST['dados']; if(!$mailfrom == "" && (!strstr($mailfrom,"@") || !strstr($mailfrom,"."))) { echo "

Volte e digite um email valido.

\n"; $badinput = "

O Contato não foi enviado.

\n"; echo $badinput; die ("Retorne..."); } if(empty($nome) || empty($mailfrom) || empty($tel) || empty($dados)) { echo "

Os campos Nome, Email, Telefone e Comentário são obrigatórios.

\n"; die ("Retorne..."); } $subject = $contato; $dados = stripcslashes($dados); $message = "Aos cuidados de: $contato \n"; $message .= "Mensagem: $dados \n"; $message .= "De: $nome ($mailfrom)\n"; $message .= "Celular: $cel \n"; $message .= "Telefone: $tel \n"; $from = "De: $mailfrom \r\n"; $to = $contato; $headers .= "From:\r\n"; $headers .= "Reply-To:\r\n"; $headers .= "X-Mailer: PHP/".phpversion(); mail($to, $subject, $message, $from, $headers); ?>

Data: <?php echo $todayis ?>
Obrigado : <?php echo $nome ?> ( <?php echo $mailfrom ?> )

Contato: <?php echo $contato ?>


<?php $notesout = str_replace("\r", "
", $dados); echo $notesout; ?>

<?php echo $to, "
", "
", $subject, "
", $message, "
", $from ?>

Voltar para o WebSite


Remove the $from, bit from the mail line… headers replaces it completely.

You should have:

mail($to, $subject, $message, $headers);
That should do the trick.

Also bear in mind that in the confirmation “echo” you’re displaying the $from var, however in the actual email, you’re sending it to a fix address in the "$header = ‘From:’ " part.


web design, development & seo by DigitalVibe


I don’t know how to thank you…

It’s Working now.
I’ve made some changes and now it’s great…

Thanks again…
CyA !!!