Am încercat să trimiteți un e-mail prin GMail's SMTP server dintr-o pagina PHP, dar primesc eroarea asta:
autentificare eșec [SMTP: SMTP server nu are nici un sprijin de autentificare (cod: 250, răspuns: mx.google.com la dispoziția dumneavoastră, [98.117.99.235] DIMENSIUNE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES CONDUCTE)]
Poate ajuta cineva? Aici este codul meu:
<?php
require_once "Mail.php";
$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.gmail.com";
$port = "587";
$username = "[email protected]";
$password = "testtest";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'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>");
}
?>
// Pear Mail Library
require_once "Mail.php";
$from = '<[email protected]>';
$to = '<[email protected]>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => '[email protected]',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
Folosind Swift mailer, este destul de ușor de a trimite un e-mail prin Gmail autentificare:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('GMAIL_USERNAME')
->setPassword('GMAIL_PASSWORD');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('[email protected]' => 'ABC'))
->setTo(array('[email protected]'))
->setBody('This is a test mail.');
$result = $mailer->send($message);
?>
Codul tău nu pare să fie folosind TLS (SSL), care este necesar pentru a livra e-mail la Google (și folosind porturi 465 sau 587)]1.
Puteți face acest lucru prin setarea
$host = "ssl://smtp.gmail.com";
Codul pare suspect ca acest exemplu, care se referă la https:// în hostname sistem.
Eu nu't recomanda Pere Mail. Acesta nu a fost actualizat din anul 2010. Citiți, de asemenea, fișierele sursă; codul sursă este aproape depășite, scris în PHP 4 stil și multe erori / bug-uri au fost postate (Google it). Eu sunt, folosind Swift Mailer.
Swift Mailer se integrează în orice aplicație web scrisă în PHP 5, care oferă un sistem flexibil și elegant abordare orientată spre obiect pentru a trimite e-mailuri cu o multitudine de caracteristici.
Trimite e-mailuri prin SMTP, sendmail, postfix sau un obicei de Transport punerea în aplicare a ta.
Suport servere care necesită nume de utilizator & parola și/sau criptare.
de a Proteja, de la antet injecție atacuri fără stripping cerere de date conținut.
Trimite MIME compatibil HTML/mai multe e-mailuri.
Folosiți-determinate de un eveniment plugin-uri pentru a personaliza biblioteca.
Mâner atașamente mari și inline/imagini încorporate cu memorie redus utilizați.
Acesta este un program gratuit și open source puteți Descărcare Rapidă Mailer și încărcați la server. (Lista caracteristică este copiat de la proprietarul site-ului).
Exemplul de lucru de Gmail SSL/SMTP și Swift Mailer este aici...
// Swift Mailer Library
require_once '../path/to/lib/swift_required.php';
// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('[email protected]') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password
// Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('[email protected]' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('[email protected]' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the <strong>message</strong> itself. It can be text or <h1>HTML</h1>.', 'text/html');
// Send the message
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
Sper că acest lucru ajută. Codificare fericit... :)
<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('[email protected]', 'PRSPS');
//$mail->AddReplyTo("[email protected]', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
SwiftMailer pot trimite E-Mail folosind servere externe.
aici este un exemplu care arată cum să utilizați un server Gmail:
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Connect to an IP address on a non-standard port
$swift =& new Swift(new Swift_Connection_SMTP("217.147.94.117", 419));
//Connect to Gmail (PHP5)
$swift = new Swift(new Swift_Connection_SMTP(
"smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
Trimite e-Mail folosind phpMailer bibliotecă prin Gmail Vă rugăm să donwload fișiere bibliotecă de Github
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Am avut această problemă, de asemenea. Am stabilit setările corecte și au activat mai puțin sigure aplicații, dar tot nu a mers. În cele din urmă, am activat această https://accounts.google.com/UnlockCaptcha și ea a lucrat pentru mine. Sper că acest lucru ajută cineva.
Am incercat sugestia oferită de @shasi kanth, dar nu't lucra. Am citit documentația și există câteva schimbări. Așa am reușit să-trimite e-mail prin Gmail folosind acest cod, în cazul în care vendor/autoload.php este luat de compozitor cu compozitorul necesită "swiftmailer/swiftmailer:^6.0":
`` <?php require_once 'furnizor/autoload.php'; $transportul = (nou Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))->setUsername ('SendingMail')->setPassword ('Parola');
$mailer = new Swift_Mailer($transport);
$mesaj = (nou Swift_Message('de testare')) ->setFrom(['Trimiterea de e-mail']) ->stabilite pentru(['Destinatarul e-mail']) ->setBody('Mesaj') ;
$rezultat = $mailer->trimite($mesaj); ?> ``
Am o soluție pentru GSuite conturile care nu au "@gmail.com" sufix. De asemenea, cred că va lucra pentru GSuite conturile cu @gmail.com dar am încercat. În primul rând, ar trebui să aveți privilegii pentru a schimba opțiunea "allos¿w mai puțin sigure app" pentru GSuite cont. Dacă aveți privilegiile (puteți verifica în considerare setări->securitate), atunci va trebui să dezactivați "pasul doi factor de autentificare" du-te la sfârșitul paginii și setat la "da" pentru a permite mai puține aplicații sigure. Ca's toate. Dacă nu aveți privilegiile necesare pentru a modifica aceste opțiuni soluția pentru acest thread nu va funcționa. Verifica https://support.google.com/a/answer/6260879?hl=en pentru a face modificări la "permite mai puțin..." opțiune.