2012-11-09 28 views
5

का उपयोग करके एक ईमेल भेजना मैंने कई अलग-अलग दृष्टिकोणों की कोशिश की है, लेकिन mail() फ़ंक्शन का उपयोग करके PHP में SMTP के माध्यम से सफलतापूर्वक ईमेल भेज नहीं सकते हैं।वर्डप्रेस

<?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."; 
?> 

मैं क्या गलत कर रहा हूं?

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

आपका त्रुटि संदेश पूरा नहीं हुआ है, लाइन संख्या गुम है। उस लाइन नंबर पर जाएं, और हमें बताएं कि पिछली पंक्तियों में कोड क्या है। त्रुटि वहाँ है। – Jocelyn

+0

मैंने अपना कोड अपडेट किया है, त्रुटि लाइन 8 में है plz chk अब यह – user1811549

+0

भले ही आपके द्वारा पोस्ट किया गया कोड सही नहीं है, मुझे कोई गंभीर त्रुटि दिखाई नहीं दे रही है जो पार्स त्रुटि का कारण बन सकती है। क्या यह वास्तव में आपके द्वारा पोस्ट की गई 'content.php' का कोड है? – Jocelyn

उत्तर

1

यह:

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

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

इस होना चाहिए:

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

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

भी हो, यह आप एक ई-मेल भेजने के लिए कोशिश कर रहे हैं मैं निम्न त्रुटि हो रही है PHPMailer क्लास और मेल() देशी PHP फ़ंक्शन दोनों के माध्यम से। आप बस परीक्षण कर सकते हैं लेकिन मुझे सच में यकीन नहीं है कि आप क्या करने की कोशिश कर रहे हैं।

+0

आपके_मेसेज में सिंगल कोट्स को लागू करने के बाद, पिछले त्रुटि के समान त्रुटि – user1811549

+0

कृपया मुझे बताएं कि मैं PHPMailer क्लास या मेल() फ़ंक्शन – user1811549

+0

@digitalis के माध्यम से smtp का उपयोग करके मेल कैसे भेज सकता हूं, आप गायब सिंगल कोट्स के बारे में सही हैं, लेकिन यह वास्तव में नहीं है पार्स त्रुटि का कारण। एक सरणी कुंजी के चारों ओर एक लापता एकल उद्धरण एक नोटिस या चेतावनी का कारण बनता है, त्रुटि नहीं। – Jocelyn