Skip to content

Instantly share code, notes, and snippets.

@koffisani
Created December 27, 2016 22:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koffisani/70bcbbd61f1c24c1ab2d9dafcc011875 to your computer and use it in GitHub Desktop.
Save koffisani/70bcbbd61f1c24c1ab2d9dafcc011875 to your computer and use it in GitHub Desktop.
Sending mail in PHP with native mail function
<?php if(isset($_POST['submit'])){
if(isset($_POST['email']) && !empty($_POST['email']) && isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['subject']) && !empty($_POST['subject']) && isset($_POST['message']) && !empty($_POST['message'])){
$to = "contact@micronium.net";
$subject = $_POST['subject'];
$message = $_POST['message'];
//$header = "Name= " .
$header = "From:" . $_POST['name'] . " <" . $_POST['email'] . "> \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$header .= "X-Mailer: PHP/" . phpversion();
$status = mail($to, $subject, $message, $header);
#$stat = //sendMail();
?>
<?php if($status == TRUE){ ?>
<div class="alert alert-success alert-dismissable" id="contactSuccess">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Succès!</strong> Votre message a été bien envoyé.
</div>
<?php }
else { ?>
<div class="alert alert-danger " id="contactError">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Erreur!</strong> Il y a eu problème lors de l'envoi de votre message. SVP réessayez !
</div>
<?php }
}else{
?>
<div class="alert alert-danger ">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Erreur!</strong> Veuillez renseigner tous les champs !
</div>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment