Created
December 27, 2016 22:16
-
-
Save koffisani/70bcbbd61f1c24c1ab2d9dafcc011875 to your computer and use it in GitHub Desktop.
Sending mail in PHP with native mail function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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">×</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">×</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">×</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