Yuav Xa Email Los ntawm PHP Script Siv SMTP Authentication

Cov txheej txheem:

Yuav Xa Email Los ntawm PHP Script Siv SMTP Authentication
Yuav Xa Email Los ntawm PHP Script Siv SMTP Authentication
Anonim

Yuav Paub

  • PHP chav xaiv: PHPmailer, SwiftMailer, Zend_Mail, XpertMailer, PEAR Mail.
  • PEAR Mail: Nco ntsoov mail server lub npe > xyuas tias PEAR Mail tau teeb tsa > hloov kho PHP cov ntaub ntawv siv cov piv txwv muab.

Kab lus no piav qhia yuav ua li cas siv SMTP authentication xa email nrog PHP mail() ua haujlwm hauv PEAR Mail.

Xa Email Nrog PHP Mail Function

Thaum koj siv PHP mail() muaj nuj nqi, koj xaus xa email ncaj qha los ntawm koj lub vev xaib server es tsis yog koj xa email. Yog tias koj muaj email server los ntawm koj lub vev xaib, lossis txawm tias xa ntawv xa nrog tus tswv tsev sib txawv, feem ntau nws yog qhov zoo dua los xa ntawv los ntawm qhov ntawd.

Qhov teeb meem yog tias PHP mail() muaj nuj nqi tsis muab ib txoj hauv kev xa ntawv los ntawm SMTP. Yog tias koj xav qhib qhov kev ua haujlwm ntawd, koj yuav tsum tau nruab ib chav kawm PHP ntxiv.

Nov yog qee qhov kev xaiv ua haujlwm:

  • PHPmailer
  • SwiftMailer
  • Zend_Mail
  • XpertMailer
  • PEAR Mail

Peb yuav qhia koj siv PEAR Mail, tab sis koj tuaj yeem siv txhua chav kawm uas txhawb nqa SMTP.

Image
Image

Yog tias koj lub vev xaib twb muaj ib lossis ntau dua ntawm cov chav kawm no tau teeb tsa, nws tej zaum yuav muaj kev qhia txog koj qhov xwm txheej. Yog tias muaj, mus tom ntej thiab siv cov chav kawm uas koj nkag tau mus.

Tsuas siv hom no yog tias koj siv PHP los tsim koj tus kheej cov ntawv xa ntawv. Yog tias koj tab tom siv cov txheej txheem tswj hwm cov ntsiab lus (CMS) zoo li WordPress, nrhiav lub plugin lossis ua haujlwm ua haujlwm xa tuaj ntawm SMTP, tsis yog sim tsim koj tus kheej.

Yuav ua li cas siv PEAR xa ntawv ntawm SMTP

  1. Nco ntsoov tias koj lub npe tau taw qhia ntawm Mail Exchange (MX) cov ntaub ntawv ntawm koj tus tswv tsev xa ntawv thiab nco ntsoov koj lub npe xa ntawv. Piv txwv li, nws yuav yog mail.yourdomain.net lossis smtp.yourdomain.net.
  2. Kuaj saib seb PEAR Mail twb tau teeb tsa rau ntawm koj lub mail server.
  3. Yog PEAR Mail tsis tau teeb tsa, sab laj nrog koj lub vev xaib xa ntawv rau cov lus qhia tshwj xeeb rau nruab nws.
  4. Ib zaug PEAR Mail raug teeb tsa, hloov kho ib qho piv txwv PHP cov ntaub ntawv hauv cov ntu hauv qab no kom haum koj cov kev xav tau.

Example PEAR Mail PHP Script For SMTP Mail

Koj tuaj yeem tsim koj tus kheej tsab ntawv los ntawm kos yog tias koj nyiam, lossis hloov cov qauv hauv qab no rau koj nyiam. Nco ntsoov nkag mus rau koj lub vev xaib xa ntawv lub npe nyob rau hauv tus tswv tsev hloov pauv, thiab siv koj cov ntaub ntawv nkag rau koj lub vev xaib xa ntawv hauv lub npe siv thiab lo lus zais.

require_once "Mail.php";

$from="Sender Name";

$to="Recipient Name";

$subject="Txoj kab Ntawm no: ";

$body=" tej lus koj xav tau ";

$host="yourmailhost.com";

$username="koj tus neeg siv lub npe lossis email";$password="koj tus password";

$headers=array ('From'=> $from, 'To'=> $to, 'Subject'=> $subject);

$smtp=Mail::factory('smtp', array ('host'=> $host, 'auth'=> tseeb, 'username'=> $username, 'password'=> $password));

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

if (PEAR::isError($mail)) {

echo("

". $mail->getMessage()."

);

} else {echo("

Txoj lus xa tiav!

);}

Piv txwv PEAR Xa Ntawv PHP Script Rau SMTP Authentication thiab SSL Encryption

Yog tias koj xav siv SMTP authentication thiab SSL encryption, koj yuav tau hloov kho ob peb yam piv txwv yav dhau los. Koj yuav tsum tau taw qhia tus tswv tsev hloov pauv mus rau koj tus neeg xa ntawv SSL, thiab tseem qhia tus lej chaw nres nkoj xws li 25, 465, 587, 2525 lossis 8025. Hu rau koj lub vev xaib xa ntawv yog xav paub ntau ntxiv yog tias koj tsis tuaj yeem txheeb xyuas qhov chaw nres nkoj rau siv.

require_once "Mail.php";

$from="Sender Name";

$to="Recipient Name";

$subject="Txoj kab ntawm no: ";

$body=" tej lus koj xav tau ";

$host="ssl://yourmailhost.com";

$port="587"; $username="koj tus username lossis email";

$password="koj tus password";

$headers=array ('Los'=> $from, ' To'=> $to, 'Subject'=> $subject);

$smtp=Mail::factory('smtp', array ('host'=> $host, 'port'=> $port, 'auth'=> tseeb, 'username'=> $username, 'password'=> $password));

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

if (PEAR::isError($mail)) {

echo("

". $mail->getMessage()."

);

} else {echo("

Txoj lus xa tiav!

);}

Pom zoo: