2008-08-30 11 views
11

का उपयोग कर PHP मेल मेरे PHP वेबएप में, जब भी कुछ त्रुटियां होती हैं, तो मैं ईमेल के माध्यम से अधिसूचित होना चाहता हूं। मैं इन्हें भेजने के लिए अपने जीमेल खाते का उपयोग करना चाहता हूं। यह कैसे किया जा सकता है?जीमेल

उत्तर

8

जीमेल के SMTP सर्वर एक बहुत विशिष्ट विन्यास की आवश्यकता है।

Gmail help से

:

Outgoing Mail (SMTP) Server (requires TLS) 
- smtp.gmail.com 
- Use Authentication: Yes 
- Use STARTTLS: Yes (some clients call this SSL) 
- Port: 465 or 587 
Account Name: your full email address (including @gmail.com) 
Email Address: your email address ([email protected]) 
Password:  your Gmail password 

आप शायद Pear::Mail या PHPMailer में इन सेटिंग्स को सेट कर सकते हैं। अधिक जानकारी के लिए उनके दस्तावेज देखें।

4

आप Gmail की एसएमटीपी सर्वर

ध्यान दें कि जब ई-मेल भेजने जीमेल के SMTP सर्वर का उपयोग कर, यह दिखेगा ऐसा आपके Gmail पते से आया था, के साथ नाशपाती के मेल समारोह इस्तेमाल कर सकते हैं कि तुम क्या मूल्य $ से के लिए है के बावजूद।

(निम्नलिखित कोड About.com Programming Tips से लिया)

<?php 
require_once "Mail.php"; 

$from = "Sandra Sender <[email protected]>"; 
$to = "Ramona Recipient <[email protected]>"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 

// stick your GMAIL SMTP info here! ------------------------------ 
$host = "mail.example.com"; 
$username = "smtp_username"; 
$password = "smtp_password"; 
// -------------------------------------------------------------- 

$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    'auth' => true, 
    'username' => $username, 
    'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
    echo("<p>" . $mail->getMessage() . "</p>"); 
} else { 
    echo("<p>Message successfully sent!</p>"); 
} 
?>