XAMPP Sendmail с использованием учетной записи Gmail
Я пытаюсь настроить Sendmail через XAMPP для отправки электронной почты. В моем sendmail.ini у меня есть следующие настройки:
# Set default values for all following accounts.
logfile "C:\xampp\sendmail\sendmail.log
account Gmail
tls on
port 587
tls_certcheck off
host smtp.gmail.com
from [email protected]
auth on
user [email protected]
password mypassword
account default : Gmail
Я создал тест script следующим образом:
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: [email protected]" . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo ("Message successfully sent!");
} else {
echo ("Message delivery failed...");
}
Я получаю сообщение, чтобы сказать, что письмо было отправлено, но оно никогда не приходит и в журналах, которые я получаю:
sendmail: Ошибка при доставке: сначала необходимо выполнить команду STARTTLS.
Кто-нибудь знает, что может быть здесь?
Спасибо заранее!
Газ
Ответы
Ответ 1
Это то, что сработало для меня. Надеюсь, никто больше не сгорит масло, чтобы понять это, как я.
Вот мой sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=yourgmailpassword
[email protected]
php/php.ini ---- в основном комментировать все, кроме sendmail_path и mail.add_x_header
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\apache\logs\php_mail.log"
Это сработало для меня после того, как я обновил файлы sendmail (старые не поддерживают smtp)
- перейдите в http://glob.com.au/sendmail/ и возьмите последний почтовый файл sendmail
- разархивируйте рабочий стол и скопируйте файлы в папку \xampp\sendmail, заменив все, что было там. ВСЕ!
- Теперь откройте sendmail.ini и скопируйте то, что я показал выше. (сначала удалите все в этом файле или просто прокомментируйте все!)
- ПРИМЕЧАНИЕ. Для этого вам не нужны серверы Mercury.
Я делал php восстановления пароля на localhost, когда я столкнулся с этой проблемой. Мне нужно было отправить пользователям свой пароль.
- ваш php выглядит okey
Ответ 2
Хорошо, сегодня лучший ответ мне не помог. Но это произошло:
в sendmail.ini:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=****@gmail.com
auth_password=*******
force_sender=****@gmail.com
в php.ini:
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
На основе порта @: http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
Ответ 3
Все, что мне нужно было сделать, - это включить "Разрешить менее безопасные приложения для доступа к вашей учетной записи". Я думаю, это альтернатива созданию определенного для приложения пароля.
https://support.google.com/accounts/answer/6010255 для информации
https://www.google.com/settings/security/lesssecureapps для коммутатора
Возможно, стоит отключить его после того, как вы закончите в целях безопасности.
Ответ 4
Это самые последние требования к серверу SMTP для Google:
- Адрес сервера SMTP Gmail: smtp.gmail.com
- Пароль SMTP для Gmail: (ваш пароль Gmail)
- Порт SMTP Gmail (TLS): 587
- SMTP-порт Gmail (SSL): 465
- Требуется Gmail SMTP TLS/SSL: Да
Требования к SMTP Google
Если вы просто используете SSL, он становится сложным с требуемым тестом проверки Captcha, поэтому я просто устанавливаю свой SSL на авто, который будет пытаться использовать TLS при сбое SSL.
![введите описание изображения здесь]()
Ответ 5
Просто добавьте к уже отличным ответам. Убедитесь, что вы используете XAMPP в качестве администратора. Это было исправлено для меня.
Ответ 6
a) Измените php.ini
Найдите php.ini в пути к файлу "[Буква диска]: [Каталог XAMPP]\php". например C:\XAMPP\PHP\php.ini
Найдите sendmail_path
в вашем файле php.ini и удалите полуплотность ";" прежде чем [у меня не было пути].
[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [your_gmail_username]@gmail.com
sendmail_path = "\"C:\xampplite\sendmail\sendmail.exe\" -t"
b) Измените sendmail.ini
Найдите путь к файлу sendmail.ini: "[Буква диска]: [каталог XAMPP]\sendmail", например. C:\XAMPP\Sendmail\sendmail.ini
Прокомментируйте содержание "Меркурий" и "Пример бесплатной почтовой службы" в качестве
ниже:
# Mercury <br/>
#account Mercury <br/>
#host localhost <br/>
#from [email protected] <br/>
#auth off <br/>
# A freemail service example <br/>
#account Hotmail <br/>
#tls on <br/>
#tls_certcheck off <br/>
#host smtp.live .com <br/>
#from [exampleuser]@hotmail.com <br/>
#auth on <br/>
#user [exampleuser]@hotmail .com <br/>
#password [examplepassword] <br/>
с. Добавьте учетную запись gmail.
Пример:
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from [your_gmail_username]@gmail.com
auth on
account default : Gmail
д. Перезапустить сервер Apache
Я не использовал gmail. Я использовал свою учетную запись хостинга. Если вы это сделаете, убедитесь, что настройки SMTP верны. Мой был mail.abc.com, а не smtp.gmail.com.
Этот код состоит из 2 веб-сайтов. Вам нужно изменить оба файла.
Я работаю над Xampp 1.73, работающим на коробке win200sp4. Все настройки по умолчанию, за исключением этих двух файлов. php.ini и sendmail.ini
Ответ 7
При использовании Gmail возникает другая проблема. Теперь у Gmail есть безопасность, поэтому вы должны создать специальный пароль для приложения - вы не можете использовать пароль, который у вас есть для обычного доступа к Gmail. Я обнаружил это, попробовав приведенные выше примеры, а затем заметил, что в папке sendmail был создан журнал ошибок. В журнале ошибок я столкнулся с сообщением об этом.
Ответ 8
Я знаю, что это старая должность, но просто подумал, что я поделюсь фактом, что для меня это работало.
В настоящее время я использую WAMP-сервер в Windows 7 ENT с Apache/2.4.9 (Win64) PHP/5.5.12 и MySQL 5.6.17.
Я следовал этому руководству: http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
Ответ 9
THIS IS WHAT YOU SENDMAIL SHOULD LOOK LIKE
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=465
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = always use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=auto
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify
;default_domain=mydomain.com
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=Your Email Here
auth_password=Your Password Here
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.
pop3_server=
pop3_username=
pop3_password=
; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
force_sender=Your Email Here
; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content
force_recipient=
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
hostname=smtp.gmail.com
THIS IS WHAT YOU PHP.INI FILE SHOULD LOOK LIKE
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
smtp_server=smtp.gmail.com
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header=Off