SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output $mail->isSMTP(); //Send using SMTP $mail->Host = $smtp_host; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = $smtp_username; //SMTP username $mail->Password = $smtp_password; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above //Recipients $mail->setFrom($smtp_from, 'Mailer'); foreach ($smtp_addresses as $address) { $mail->addAddress($address['email'], $address['user']); //Add a recipient } $mail->addReplyTo($email, $name); // $mail->addCC('cc@example.com'); // $mail->addBCC('bcc@example.com'); //Attachments // $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name //Content $mail->isHTML(true); $mail->CharSet = 'UTF-8'; $mail->Encoding = 'base64'; //Set email format to HTML $mail->Subject = $subject; $content = ""; $content .= "Message en provenance de la page contact des cocottes:
"; $content .= "De: ".$name.' '.$email."
"; if ($website != "") { $content .= 'Site web: ' . $website ."
"; } $content .= "
"; $content .= $message; $mail->Body = $content; $mail->AltBody = $message; $mail->send(); $_SESSION['msg'] .= "Votre gazouilli a bien été envoyé \\o/.\n"; } catch (Exception $e) { $_SESSION['error_msg'] .= "Votre gazouilli n'a malheureusement pas pu être envoyé. \n Mailer Error: {$mail->ErrorInfo}"; } } $_SESSION['error_msg'] = ""; $_SESSION['msg'] = ""; if (isset($_POST['submit'])) { if (isset($_POST['name']) and $_POST['name'] != "") { $name = $_POST['name']; } else { $_SESSION['error_msg'] .= "Mais quel est votre nom, chère cocotte ?\n"; } if (isset($_POST['email']) and $_POST['email'] != "") { $email = $_POST['email']; } else { $_SESSION['error_msg'] .= "Et votre email ?\n"; } if (isset($_POST['website']) and $_POST['website'] != "") { $website = $_POST['website']; } else { $website = ""; } if (isset($_POST['subject']) and $_POST['subject'] != "") { $subject = $_POST['subject']; } else { $_SESSION['error_msg'] .= "De quoi voulez vous nous parler ?"; } if (isset($_POST['message']) and $_POST['message'] != "") { $message = $_POST['message']; } else { $_SESSION['error_msg'] .= "Vous caqueter bien faiblement ma pauvre cocotte, vous n'aviez rien à nous dire ?\n"; } } else { $_SESSION['error_msg'] .= "Vous n'avez pas soumis le formulaire de contact.\n"; } if ($_SESSION['error_msg'] == "") { send($name, $email, $website, $subject, $message); } // echo $_SESSION['error_msg']; // echo $_SESSION['msg']; header('Location: /contact'); ?>