I am creating a contact form from a bootstrap template. However, I would like to retrieve the values of the fields entered by the user in order to receive them by email on my contact address. I would like to retrieve the ID fields (name, prenom, email, contact-phone, input_from, input_to and message)
My PHP Mailer file works correctly, but I can't get the desired effect. Second error, I have predefined messages for sending or failing mail in my HTML file, how can I use it?
Can you help me with this?
PHP CODE :
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require ("../PHPMailer-master/src/PHPMailer.php");
require ("../PHPMailer-master/src/SMTP.php");
require ("../PHPMailer-master/src/Exception.php");
date_default_timezone_set("Europe/Paris");
$mail = new PHPMailer();
$body = "Test de PHPMailer.";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPOptions = array('ssl' => array('verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true)); // ignorer l'erreur de certificat.
$mail->Host = "mail.xxxx.com";
$mail->Port = 587;
$mail->Username = "test@xxxx.com";
$mail->Password = "xxxx";
$mail->From = "test@xxxx.com"; //adresse d’envoi correspondant au login entré précédemment
$mail->FromName = "Nouveau message sur le site "; // nom qui sera affiché
$mail->Subject = "Nouveau message"; // sujet
$mail->AltBody = "corps du message au format texte"; //Body au format texte
$mail->WordWrap = 50; // nombre de caractères pour le retour à la ligne automatique
$mail->MsgHTML($_POST['name']);
$mail->MsgHTML($_POST['prenom']);
$mail->MsgHTML($_POST['email']);
$mail->MsgHTML($_POST['message']);
$mail->AddReplyTo("votre mail","votre nom");
//$mail->AddAttachment("./examples/images/phpmailer.gif");// pièce jointe si besoin
$mail->AddAddress("xxxxxxxxxxxxxxxxx");
$mail->IsHTML(true); // envoyer au format html, passer a false si en mode texte
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Le message à bien été envoyé";
}
?>
HTML CODE :
<form action="contact-2.php" method="post" role="form" class="php-email-form">
<div class="row">
<div class="form-group col-md-6">
<input type="text" name="name" class="form-control" id="name" placeholder="Nom" required>
</div>
<div class="form-group col-md-6">
<input type="text" class="form-control" name="prenom" id="prenom" placeholder="Prénom" required>
</div>
<div class="form-group col-md-6">
<input type="email" class="form-control" name="email" id="email" placeholder="Email" required>
</div>
<div class="form-group col-md-6">
<input type="tel" class="form-control" name="subject" id="contact-phone" placeholder="Téléphone" required>
</div>
<div class="form-group col-md-6">
<input type="text" class="form-control" id="input_from" placeholder="A partir du :" required>
</div>
<div class="form-group col-md-6">
<input type="text" class="form-control" id="input_to" placeholder="Au :" required>
</div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="6" placeholder="Message" required></textarea>
</div>
<div class="my-3">
<div class="loading">Envoi en cours</div>
<div class="error-message"></div>
<div class="sent-message">Votre message a été envoyé. Merci !</div>
</div>
<div class="text-center"><button type="submit">Envoyer</button></div>
</form>
</div>
source https://stackoverflow.com/questions/71313252/sending-information-from-an-html-page-with-php-mailer
No comments:
Post a Comment