2016-07-28 10 views
0

Ich habe ein contact_me.php Formular für eine Bootstrap-Website, an der ich arbeite, und ich musste PHPMailer hinzufügen, um SMTP-Authentifizierung für das Kontaktformular zu haben. Ich bin nicht sicher, wo ich den PHPMailer php für die SMTP-Authentifizierung innerhalb der contact_me.php hinzufügen. Momentan funktioniert das Kontaktformular Ich erhalte nur die gesendeten E-Mails nicht. Vielen Dank!Hinzufügen von SMTP zu Bootstrap contact_me.php

contact_me.php 

<?php 
// check if fields passed are empty 
if(empty($_POST['name'])  || 
empty($_POST['phone'])  || 
empty($_POST['email'])  || 
empty($_POST['message']) || 
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
{ 
echo "No arguments Provided!"; 
return false; 
} 

$name = $_POST['name']; 
$phone = $_POST['phone']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

// create email body and send it  
$to = '[email protected]'; // PUT YOUR EMAIL ADDRESS HERE 
$email_subject = "Website Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE 
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail:          $email_address\n\nMessage:\n$message"; 
$headers = "From: [email protected]\n"; 
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers); 
return true;    
?> 

und der PHPMailer Code:

require_once('path/to/library/class.phpmailer.php'); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); 

$mail->SMTPAuth = true; 
$mail->Host = "smtp.postmarkapp.com"; 
$mail->Port = 26; 
$mail->Username = "#@#@#@#@-####[email protected]@@@-#####[email protected]#@#@#@#@#@#"; 
$mail->Password = "#@#@#@#@-####[email protected]@@@-#####[email protected]#@#@#@#@#@#"; 

$mail->SetFrom('[email protected]', 'Web App'); 
$mail->Subject = "A Transactional Email From Web App"; 
$mail->MsgHTML($body); 
$mail->AddAddress($address, $name); 

if($mail->Send()) { 
echo "Message sent!"; 
} else { 
echo "Mailer Error: " . $mail->ErrorInfo; 
} 
+0

Wer schicken Sie in den PHPMailer Code? –

+0

Es wird die gleiche Person sein wie "$ to = '[email protected]'" in der contact_me.php – Andrea

+0

Ich kann nicht sehen, wo $ Adresse initialisiert wird, deshalb fragte ich –

Antwort

Verwandte Themen