2011-02-09 51 views
18

Tôi đang cố định cấu hình Sendmail thông qua XAMPP để gửi email. Trong sendmail.ini của tôi, tôi có các thiết lập này:XAMPP Sendmail bằng tài khoản Gmail

# 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 

tôi đã tạo ra một kịch bản thử nghiệm như thế này:

$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..."); 
} 

tôi nhận được một thông điệp nói rằng email đã được gửi nhưng nó không bao giờ đến và trong nhật ký tôi nhận được:

sendmail: Lỗi khi gửi: Trước tiên, phải phát hành lệnh STARTTLS.

Có ai biết vấn đề có thể ở đây không?

Cảm ơn trước!

Gaz

+0

Tôi là người duy nhất nhận thấy, OP đó hỏi về ** bản gốc 'sendmail' ** - tác nhân chuyển thư nổi tiếng nhất thế giới ([info at Wiki] (http://en.wikipedia.org/wiki)/Sendmail)), bắt đầu vào năm 1979, trong khi hầu hết các câu trả lời là về ** fake 'sendmail' ** ([homepage] (http://glob.com.au/sendmail/)) - một chương trình giả được sử dụng trong các gói máy chủ phát triển, như XAMPP, bắt đầu năm 2004. Bạn có thể thấy mọi người, ví dụ về tệp cấu hình do OP cung cấp khác với các ví dụ cấu hình mà bạn đưa ra trong các câu trả lời của mình không? Lạ thật. – trejder

Trả lời

35

Đây là những gì đã làm việc cho tôi Hy vọng rằng sẽ không có ai đốt dầu để hình dung ra như tôi đã làm.

Đây là sendmail.ini tôi

[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 ---- cơ bản bình luận mọi thứ trừ 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" 

này làm việc cho tôi sau khi tôi cập nhật các tệp sendmail (các tệp cũ không hỗ trợ smtp)

  • chuyển đến http://glob.com.au/sendmail/ một d lấy tệp zip mới nhất của sendmail
  • giải nén vào máy tính để bàn và sao chép các tệp vào thư mục \ xampp \ sendmail của bạn thay thế mọi thứ đã có ở đó.EVERYTHING!
  • Bây giờ hãy mở sendmail.ini và sao chép dán những gì tôi đã hiển thị ở trên. (Xóa tất cả mọi thứ trong tệp đó trước hoặc chỉ bình luận mọi thứ!)
  • LƯU Ý: bạn không cần máy chủ Mercury bắt đầu.

Tôi đã tạo một mật khẩu khôi phục mật khẩu trên máy chủ cục bộ khi gặp sự cố này. Tôi cần gửi mật khẩu cho người dùng. - php của bạn trông okey

+1

Điều này làm việc rực rỡ cho tôi. Chỉ cần thêm một lưu ý tiết kiệm thời gian: Nhớ khởi động lại Apache sau khi thay đổi các tập tin cấu hình. – KalenGi

+0

Bạn nói "những cái cũ không hỗ trợ smtp", nhưng tôi nghĩ bạn có nghĩa là "cái cũ không hỗ trợ TLS." – D0SBoots

+1

Tôi có thêm 2 ghi chú: 1) Tôi phải bật các ứng dụng kém an toàn hơn để truy cập tài khoản Gmail của mình (truy cập Gmail> Tài khoản> Bảo mật); 2) Tôi đã phải sử dụng cổng 587 thay vì 25. – FlavioEscobar

0

a) Thay đổi php.ini Định vị tệp php.ini trong đường dẫn tệp “[Drive Letter]: [XAMPP directory] \ php”. ví dụ. C: \ xampp \ php \ php.ini

Tìm kiếm sendmail_path trong tệp php.ini của bạn và xóa dấu chấm phẩy “;” trước khi [tôi không có đường dẫn].

[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) Thay đổi sendmail.ini Xác định vị trí sendmail.ini trong đường dẫn tập tin là “[Drive Letter]: [XAMPP thư mục] \ sendmail” ví dụ C: \ xampp \ sendmail \ sendmail.ini

luận là “Thủy” và “Một dịch vụ email miễn phí ví dụ” nội dung như hiển thị dưới đây:

# 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/> 

c. Thêm tài khoản gmail.

Ví dụ:

account Gmail 
tls on 
tls_certcheck off 
host smtp.gmail.com 
from [your_gmail_username]@gmail.com 
auth on 
    account default : Gmail 

d. Khởi động lại Apache Server


Tôi không sử dụng gmail. Tôi đã sử dụng tài khoản lưu trữ của mình. Nếu bạn làm điều đó, hãy chắc chắn rằng các thiết lập SMTP là chính xác. Của tôi là mail.abc.com không phải smtp.gmail.com. Mã này là từ 2 trang web. Bạn cần phải thay đổi cả hai tập tin. Tôi có nó hoạt động trên Xampp 1.73 chạy trên một hộp win200sp4. Tất cả cài đặt mặc định trừ hai tệp này. php.ini và sendmail.ini

13

Được rồi, hôm nay, câu trả lời hay nhất không phù hợp với tôi. Nhưng, điều này đã làm:

trong 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 

trong php.ini:

[mail function] 
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 

Dựa trên cổng @: http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

0

Có một vấn đề khi sử dụng Gmail. Gmail hiện có bảo mật để bạn phải tạo mật khẩu dành riêng cho ứng dụng - bạn không thể sử dụng mật khẩu bạn có cho quyền truy cập Gmail thông thường của mình. Tôi phát hiện ra điều này bằng cách thử các ví dụ trên và sau đó nhận thấy rằng trong thư mục sendmail một bản ghi lỗi đã được tạo ra. Trong nhật ký lỗi, tôi thấy một thông báo cho biết điều này.

+0

Tôi đã thử với tài khoản của mình và nó hoạt động, nhưng chỉ với cổng 465 – webeno

1

Tất cả những gì tôi phải làm là chuyển "Cho phép ứng dụng kém an toàn truy cập tài khoản của bạn" sang bật. Tôi đoán đây là một thay thế để tạo mật khẩu dành riêng cho ứng dụng.

https://support.google.com/accounts/answer/6010255 để biết

https://www.google.com/settings/security/lesssecureapps cho switch

Có thể là giá trị chuyển đổi nó trở lại tắt sau khi bạn đã hoàn tất cho các mục đích an ninh.

0

Tôi biết đây là một bài đăng cũ nhưng chỉ nghĩ rằng tôi sẽ chia sẻ một thực tế là những điều sau đây đã làm việc cho tôi.

Tôi hiện đang sử dụng máy chủ WAMP trên Windows 7 ENT với Apache/2.4.9 (Win64) PHP/5.5.12 và MySQL 5.6.17.

Tôi đi theo hướng dẫn này: http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/

+0

Trong khi liên kết này có thể trả lời câu hỏi, thì tốt hơn nên bao gồm các phần quan trọng của câu trả lời ở đây và cung cấp liên kết để tham khảo. Câu trả lời chỉ liên kết có thể trở thành không hợp lệ nếu trang được liên kết thay đổi – Marusyk

0
THIS IS WHAT YOU SENDMAIL SHOULD LOOK LIKE 


[sendmail] 

; you must change mail.mydomain.com to your smtp server, 
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup) 
; emails delivered via IIS's 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 
1

Đây là những yêu cầu Google SMTP máy chủ gần đây nhất:

  1. Gmail SMTP server address: smtp.gmail.com
  2. Gmail SMTP password: (mật khẩu Gmail của bạn)
  3. cổng Gmail SMTP (TLS):
  4. cổng Gmail SMTP (SSL):
  5. Gmail SMTP TLS/SSL yêu cầu:

Google SMTP Requirements

Nếu bạn chỉ sử dụng SSL, nó sẽ trở nên phức tạp với kiểm tra xác thực Captcha được yêu cầu vì vậy tôi chỉ đặt SSL thành tự động sẽ thử TLS khi SSL Fails.
enter image description here

1

Chỉ để thêm vào các phản hồi đã sẵn sàng. Đảm bảo bạn đang chạy XAMPP với tư cách Quản trị viên. Đó là thứ đã sửa cho tôi.

Các vấn đề liên quan