2011-10-27 10 views
5

मैं कैकमेल और एसएमटीपी सेटिंग्स का उपयोग कर एक जीमेल खाते से ईमेल भेजने की कोशिश कर रहा हूं।केकपीएचपी-2.0: मैं कैकमेल और एसएमटीपी सेटिंग का उपयोग कर जीमेल खाते से ईमेल कैसे भेज सकता हूं?

यह अच्छा होगा अगर कोई प्रक्रिया चरणबद्ध तरीके से बताए कि क्या करना है।

मैं ऐप्लिकेशन में निम्न को शामिल किया है/config/email.php =>

<?php 
class EmailConfig { 
    public $smtp = array(
     'host' => 'ssl://smtp.gmail.com', 
     'port' => 465, 
     'username' => '[email protected]', 
     'password' => 'secret' 
    ); 
} 

अब मैं कैसे "[email protected]" से किसी भी ईमेल खाते से ईमेल भेज सकते हैं?

यह CakePHP-2.0

उत्तर

9
डॉक्स से

:

आप Gmail जैसी एसएसएल SMTP सर्वर, कॉन्फ़िगर कर सकते हैं। ऐसा करने के लिए, होस्ट में उपसर्ग पर 'एसएसएल: //' डालें और तदनुसार पोर्ट मान को कॉन्फ़िगर करें। उदाहरण:

<?php 
class EmailConfig { 
    public $gmail = array(
     'host' => 'ssl://smtp.gmail.com', 
     'port' => 465, 
     'username' => '[email protected]', 
     'password' => 'secret' 
    ); 
} 

http://book.cakephp.org/2.0/en/core-utility-libraries/email.html?highlight=cakeemail#CakeEmail

2

बस from सेट है:

<?php 
$email = new CakeEmail(); 
$email->from(array('[email protected]' => 'Your Name')); 
$email->to('[email protected]'); 
$email->subject('Sent from Gmail'); 
$email->send('My message'); // or use a template etc 

यह करना चाहिए।

आप sender भी सेट करना चाहते हैं; मैं 100% नहीं हूं लेकिन मुझे लगता है कि यह आपकी वेबसाइट के माध्यम से जीमेल से "ईमेल" भेजने पर उपयोगी होगा; शायद ईमेल को स्पैम के रूप में उठाए जाने से रोकने के लिए।

$email->sender('[email protected]', 'MyApp emailer');

+0

एक आकर्षण की तरह काम –

0

मैं वर्तमान में एक gmail खाते का उपयोग कर रहा हूँ आउटबाउंड मेल भेजने के लिए। मैं टेम्पलेट्स और एक पुन: प्रयोज्य ईमेल सेटअप फ़ंक्शन का उपयोग कर रहा हूं। यहां मेरे कामकाजी कोड की एक प्रति है:

// app/controllers/users_controller.php 
function sendemail($subject, $body, $to, $template) { 
    $this->Email->smtpOptions = array(
     'port'=>'465', 
     'timeout'=>'30', 
     'host' => 'ssl://smtp.gmail.com', 
     'username'=>'[email protected]', 
     'password'=>'secret', 
    ); 
    $this->Email->delivery = 'smtp'; 
    //$this->Email->delivery = 'debug'; 
    $this->Email->from = 'Username <[email protected]>'; 
    $this->Email->to  = $to; 
    $this->Email->subject = $subject; 
    $this->set('body', $body); 
    $this->set('smtp_errors', $this->Email->smtpError); 
    $this->Email->send($content, $template); 
} 

// app/controllers/users_controller.php 
// Excerpt from new user method in users controller: 
function add() { 
    // ...other stuff 
    $body['user'] = $user['User']['username']; 
    $this->sendemail('Domain.com New User Signup!', $body, '[email protected]', 'newuser'); 
    // ...other stuff 
} 

// app/views/elements/email/text/newuser.ctp 
Everyone, 
Another new user just signed up for Domain. Stats below: 
User: <?php echo $body['user'] . "\r\r"; ?> 
Just thought you'd like to know :) 
-Janet 
+0

यह पुराना ईमेल घटक है। – shibly

0

स्विफ्टमेलर घटक का उपयोग करें; यह उपयोग करने का सबसे आसान घटक है।

http://bakery.cakephp.org/articles/mhuggins/2008/06/11/improved-swiftmailer-component

कुछ बदलाव है कि आप जबकि CakePHP 2.0 के बाद के साथ इस का उपयोग करते हुए ऐसा करने की जरूरत नहीं हैं। केकपीएचपी 2.0 एक 'ईमेल' व्यू निर्देशिका प्रदान करता है, जिसका उपयोग सभी ईमेल टेम्पलेट्स को स्टोर करने के लिए किया जाता है।

  1. बदलें सभी varpublic को घोषणाओं
  2. बदलें public $layout = 'Emails';public $viewPath = '/Emails'; को

  3. बदलें _getBodyText में पथ प्रस्तुत करना:

घटक में किए गए परिवर्तन

$body = $this->controller->render($this->viewPath . DS . 'text' . DS . $view, $this->layout . DS . 'text'.DS.'default');

  1. बदलें _getBodyHtml में पथ प्रस्तुत करना:

$body = $this->controller->render($this->viewPath . DS . 'html' . DS . $view, $this->layout . DS . 'html'.DS.'default');

  1. टिप्पणी बाहर लाइनों:

$bodyText = $this->_getBodyText($view); $message->setBody($bodyText, "text/plain");

स्विफ्टमेलर घटक एक खाली ईमेल भेजता है यदि आप HTML & टेक्स्ट सक्रिय दोनों सेट करते हैं। यह दोनों ईमेल दृश्यों से पढ़ता है & शरीर को पाठ के लिए जोड़ता है। यदि आप HTML ईमेल भेजना चाहते हैं तो इन दो पंक्तियों पर टिप्पणी करने का यही कारण है। अगर दोनों सक्रिय हो जाते हैं & तुम दोनों email.html.ctp & email.text.ctp फाइलों में सामग्री है

दूसरा कारण है, यह ईमेल (वास्तविकता में दोनों स्वरूपों हेडर में मौजूद हैं में प्रदर्शित किया जाता है कि केवल पाठ प्रारूप में एक हैडर मुद्दा बनाता है, लेकिन यह एचटीएमएल भाग & को दबाता है पाठ भाग दिखाता है)।

3

सही विन्यास है:

public $gmail = array(
    'host' => 'ssl://smtp.gmail.com', 
    'port' => 465, 
    'username' => '[email protected]', 
    'password' => 'secret', 
    'transport' => 'Smtp' 
); 

तो, परिवहन तत्व मत भूलना।

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