email php
หากเกิดเหตุการณ์ที่ Mail server บางที่ไม่ยอมรับ email จากเราที่ส่งด้วย php script โดยมี error ตามด้านล่าง

(host ezylinux.com[74.xx.xxx.xxx] said: 550-Verification failed for 550-The mail server could not deliver mail to [email protected]. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries. 550 Sender verify failed (in reply to RCPT TO command))


สาเหตุของปัญหานี้เกิดจากเราไม่ได้กำหนดค่า “Return-path” ไปใน mail header ซึ่งระบบ Mail server บางที่จะมีความเข้มงวดเรื่องนี้จึงได้ reject email จากระบบของเรา

สำหรับการแก้ไขปัญหาสามารถทำได้โดยการระบุ “Return-path” ให้กับ Mail header ซึ่งสามารถทำได้ 3 วิธีด้วยกัน คือ

  • Solution 1: mail() function
    ให้ใส่ parameter -f ไปยัง mail function ใน argument ที่ 5 ตามตัวอย่าง
    mail($toEmailAddress,$subject,$message,$headers,"-f [email protected]");
  • Solution 2: php.ini
    แก้ไขไฟล์ php.ini โดยระบุ default “Return-path” ด้วย parameter -f เข้าไปยัง sendmail_path ตามตัวอย่าง
    sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]
  • Solution 3: Apache vhost
    กำหนดค่า php value ในแต่ละ Virtual Hosts ด้วยการใส่ค่า php_admin_value ตามตัวอย่างด้านล่างเข้าไป
    php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f [email protected]"

*ในตัวอย่างนี้กำหนดให้ email สำหรับ “Return-path” คือ [email protected]

Ref: How to add default Return-path in php mail