2013-01-10 16 views
7

मैं कैसे PHPMailer साथ एसएमटीपी का उपयोग करने जानते हैं:PHPMailer डिफ़ॉल्ट कॉन्फ़िगरेशन एसएमटीपी

$mail    = new PHPMailer(); 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "mail.yourdomain.com"; // sets the SMTP server 
$mail->Username = "[email protected]"; // SMTP account username 
$mail->Password = "yourpassword";  // SMTP account password 

और यह ठीक काम करता है। लेकिन मेरा सवाल है:

डिफ़ॉल्ट रूप से इन सेटिंग्स का उपयोग करने के लिए मैं PHPMailer को कैसे कॉन्फ़िगर कर सकता हूं, ताकि जब भी मैं मेल भेजना चाहता हूं तो मुझे उन्हें निर्दिष्ट करने की आवश्यकता नहीं है?

+1

यदि यह वर्डप्रेस के बारे में है -> wordpress \ wp-include \ class-phpmailer.php फ़ाइल – swapnesh

उत्तर

14

कोई फ़ंक्शन बनाएं, और इसे शामिल करें/इसका उपयोग करें।

function create_phpmailer() { 
    $mail    = new PHPMailer(); 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Host  = "mail.yourdomain.com"; // sets the SMTP server 
    $mail->Username = "[email protected]"; // SMTP account username 
    $mail->Password = "yourpassword";  // SMTP account password 
    return $mail; 
} 

और नया PHPMailer ऑब्जेक्ट बनाने के लिए create_phpmailer() को कॉल करें।

या आप अपने स्वयं के उपवर्ग, जो मानकों सेट प्राप्त कर सकते हैं:

class MyMailer extends PHPMailer { 
    public function __construct() { 
    parent::__construct(); 
    $this->IsSMTP(); // telling the class to use SMTP 
    $this->SMTPAuth = true;     // enable SMTP authentication 
    $this->Host  = "mail.yourdomain.com"; // sets the SMTP server 
    $this->Username = "[email protected]"; // SMTP account username 
    $this->Password = "yourpassword";  // SMTP account password 
    } 
} 

और नए MyMailer का उपयोग()।

+0

क्या मैं सिर्फ class.phpmailer.php फ़ाइल को संपादित नहीं कर सकता? डिफ़ॉल्ट रूप से यह (कम से कम वर्तमान संस्करण) के साथ शुरू होता है: 'वर्ग PHPMailer { सार्वजनिक $ संस्करण =' 5.2.9 '; सार्वजनिक $ प्राथमिकता = 3; सार्वजनिक $ CharSet = 'iso-8859-1'; सार्वजनिक $ ContentType = 'text/plain'; सार्वजनिक $ एन्कोडिंग = '8 बिट'; सार्वजनिक $ ErrorInfo = ''; सार्वजनिक $ = 'root @ localhost' से; सार्वजनिक $ FromName = 'रूट उपयोगकर्ता'; '... तो अगर मैं' $ से 'के मान को बदलता हूं, तो मान लें, 'myname @ example.com' – koljanep

1

क्या मैं सिर्फ class.phpmailer.php फ़ाइल को संपादित नहीं कर सकता?

कक्षा फ़ाइलों को स्वयं संपादित करना सबसे अच्छा नहीं है क्योंकि यह कोड को बनाए रखने के लिए कठिन बनाता है। wp_mail समारोह के ही स्रोत से

/** 
    * Fires after PHPMailer is initialized. 
    * 
    * @since 2.2.0 
    * 
    * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference. 
    */ 
    do_action_ref_array('phpmailer_init', array(&$phpmailer)); 

सीधे PHPMailer वर्ग को संशोधित करने के:

0

इस हुक का उपयोग कर सकते हैं।

+0

इसके लिए कोडेक्स पृष्ठ यहां है: https://codex.wordpress.org/Plugin_API/Action_Reference/phpmailer_init – shahar

संबंधित मुद्दे