Menu

I want to send an email with PHP

Photo Kane9x
Kane9x
18 janvier 2019
Répondre
MP
I want to send an email with PHP when the user completes the HTML form, then sends the form information by email. I want to do the same site view script with the template.

I found this code but the message was not sent
< ?php

if (isset($_POST['submit'])) {

$to = $_POST['email'];

$subject = $_POST['name'];

$message = getRequestURI();

$from = "programmer@example.com";

$headers = "From:" . $from;

if (mail($to, $subject, $message, $headers)) {

echo "Mail Sent.";

}

else {

echo "failed";

}

} ?>
Photo Emmanuel
Emmanuel
18 janvier 2019
Répondre
MP
Check the manual : http://php.net/manual/en/function.mail.php

A simple example :

<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

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

Photo Kane9x
Kane9x
19 janvier 2019
Répondre
MP
oui merci beaucoup
  • Share
  • Follow