Я хочу отправить данные полей формы на идентификатор gmail, но есть ошибка [duplicate]

{
   "pageInfo": {
         "pageName": "abc",
         "pagePic": "http://example.com/content.jpg"
    },
    "posts": [
         {
              "post_id": "123456789012_123456789012",
              "actor_id": "1234567890",
              "picOfPersonWhoPosted": "http://example.com/photo.jpg",
              "nameOfPersonWhoPosted": "Jane Doe",
              "message": "Sounds cool. Can't wait to see it!",
              "likesCount": "2",
              "comments": [],
              "timeOfPost": "1234567890"
         }
    ]
}

Java code :

JSONObject obj = new JSONObject(responsejsonobj);
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i++)
{
    String post_id = arr.getJSONObject(i).getString("post_id");
    ......etc
}
357
задан skb 28 June 2014 в 00:30
поделиться

11 ответов

// Pear Mail Library
require_once "Mail.php";

$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$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' => 'johndoe@gmail.com',
        'password' => 'passwordxxx'
    ));

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

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}
334
ответ дан Nathan Tuggy 24 August 2018 в 23:19
поделиться

Отправка почты с использованием библиотеки phpMailer через Gmail Пожалуйста, загрузите файлы библиотеки из 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 = "username@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', '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!";
}
5
ответ дан Bhavin Solanki 24 August 2018 в 23:19
поделиться

Установите

'auth' => false,

Также посмотрите, работает ли порт 25.

-2
ответ дан CookieOfFortune 24 August 2018 в 23:19
поделиться

В вашем коде не используется TLS (SSL), который необходим для доставки почты в Google (и с использованием портов 465 или 587) .

Вы можете сделать это, установив

$host = "ssl://smtp.gmail.com";

. Ваш код выглядит подозрительно, как этот пример , который ссылается на ssl: // в схеме имени хоста.

53
ответ дан crb 24 August 2018 в 23:19
поделиться
28
ответ дан Deept Raghav 24 August 2018 в 23:19
поделиться

Чтобы установить Mail.php PEAR в Ubuntu, выполните следующий набор команд:

    sudo apt-get install php-pear
    sudo pear install mail
    sudo pear install Net_SMTP
    sudo pear install Auth_SASL
    sudo pear install mail_mime
2
ответ дан Nahid 24 August 2018 в 23:19
поделиться

Gmail требует порт 465, а также код из phpmailer:)

32
ответ дан Peter Mortensen 24 August 2018 в 23:19
поделиться

Код, указанный в вопросе, нуждается в двух изменениях

$host = "ssl://smtp.gmail.com";
$port = "465";

Для подключения SSL требуется порт 465.

13
ответ дан s01ipsist 24 August 2018 в 23:19
поделиться

SwiftMailer может отправлять E-Mail с помощью внешних серверов.

вот пример, который показывает, как использовать сервер 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));
20
ответ дан Sam Apostel 24 August 2018 в 23:19
поделиться

Используя Swift mailer , достаточно отправить почту через учетные данные Gmail:

<?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('abc@example.com' => 'ABC'))
  ->setTo(array('xyz@test.com'))
  ->setBody('This is a test mail.');

$result = $mailer->send($message);
?>
96
ответ дан shasi kanth 24 August 2018 в 23:19
поделиться

У меня тоже была эта проблема. Я установил правильные настройки и включил менее безопасные приложения, но он все еще не работает. Наконец, я включил этот https://accounts.google.com/UnlockCaptcha , и это сработало для меня. Надеюсь, это поможет кому-то.

3
ответ дан Strategist 24 August 2018 в 23:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: