2012-11-09 13 views
5

Çok farklı yaklaşımlar denedim, ancak mail() işlevini kullanarak PHP'de SMTP yoluyla başarıyla bir EMail gönderemiyorum.Wordpress'i kullanarak bir EMail gönderme

<?php 
require_once ABSPATH . WPINC . '/class-phpmailer.php'; 
require_once ABSPATH . WPINC . '/class-smtp.php'; 
$phpmailer = new PHPMailer(); 
$phpmailer->SMTPAuth = true; 
$phpmailer->Username = '[email protected]'; 
$phpmailer->Password = 'password01'; 
  
$phpmailer->IsSMTP(); // telling the class to use SMTP 
$phpmailer->Host       = "mail.asselsolutions.com"; // SMTP server 
$phpmailer->FromName   = $_POST[your_email]; 
$phpmailer->Subject    = $_POST[your_subject]; 
$phpmailer->Body       = $_POST[your_message];                      //HTML Body 
$phpmailer->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
$phpmailer->WordWrap   = 50; // set word wrap 
$phpmailer->MsgHTML($_POST[your_message]); 
$phpmailer->AddAddress('[email protected]/files/', 'Wordpress support'); 
//$phpmailer->AddAttachment("images/phpmailer.gif");             // attachment 
if(!$phpmailer->Send()) { 
 echo "Mailer Error: " . $phpmailer->ErrorInfo; 
} else { 
 echo "Message sent!"; 
} 
$to = $_REQUEST['to']; 
$subject = $_REQUEST['subject']; 
$message = $_REQUEST['message']; 
$from = $_REQUEST['from']; 
$headers = "From:" . $from; 

$mail = mail($to,$subject,$message,$headers); 

echo "Mail Sent."; 
?> 

Neyi yanlış yapıyorum?

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\wp-vtr\wp-content\themes\twentyeleven\content.php on line 8

$phpmailer->IsSMTP(); // telling the class to use SMTP" 
+1

Hata iletiniz tamamlanmadı, satır numarası eksik. Bu satıra gidin ve önceki satırlardaki kodun ne olduğunu bize bildirin. Hata var. – Jocelyn

+0

Kodumu güncelledim, hata şu an 8 plz chk oldu – user1811549

+0

Gönderdiğiniz kod mükemmel olmasa bile, ayrıştırma hatasına neden olabilecek ciddi bir hata göremiyorum. Gönderdiğiniz 'content.php 'kodunun gerçekten mi? – Jocelyn

cevap

1

Bu:

$phpmailer->FromName = $_POST[your_email]; 
$phpmailer->Subject = $_POST[your_subject]; 
$phpmailer->Body  = $_POST[your_message]; 

$phpmailer->MsgHTML($_POST[your_message]); 

bu şekilde olmalıdır: Neyse

$phpmailer->FromName = $_POST['your_email']; 
$phpmailer->Subject = $_POST['your_subject']; 
$phpmailer->Body  = $_POST['your_message']; 

$phpmailer->MsgHTML($_POST['your_message']); 

, bir e-posta göndermek için çalışıyoruz görünüyor aşağıdaki hatayı alıyorum hem PHPMailer sınıfı ve mail() yerli PHP fonksiyonu ile. Sadece test ediyor olabilirsin, ama ne yapmaya çalıştığına gerçekten emin değilim.

+0

tek tırnak işareti uyguladıktan sonra, aynı hata meydana geldi – user1811549

+0

plz bana nasıl PHPMailer class veya mail() işlevi aracılığıyla smtp kullanarak posta gönderebileceğimi söyle – user1811549

+0

@digitalis Eksik tek tırnaklar hakkında haklısınız, ama bu gerçekten değil ayrıştırma hatasının nedeni. Bir dizi anahtarının etrafında eksik tek bir alıntı, bir uyarı veya uyarı değil, bir hataya neden olur. – Jocelyn