duangutian1426 2018-10-23 11:27
浏览 112

PHP邮件功能不起作用 - XAMPP环境

So i have basic code in my maling.php file to send email, but with no luck - always returns "Mailing failed"

<?php
$emailTo = "{mymail}@gmail.com";
$subject = "This should work";
$body = "Hellou mark mun";
$headers = "From: {mysecondmail}@gmail.com";
if (mail($emailTo,$subject,$body,$headers)){
    echo "Email was send";
}else{
    echo "Mailing failed";
}
?>

I have tried to change configuration in my sendmail.ini and php.ini file as stated in many tutorials, but it didnt work so now my files contains just this:

;php.ini
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = {mymail}@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

and

;sendmail.ini
[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username={mymail}@gmail.com
auth_password={mypass}

If i run this with configuration and code as stated above i will get this messages in debug.log:

18/10/23 13:14:52 ** --- MESSAGE BEGIN ---
18/10/23 13:14:52 ** To: gazchamber.music@gmail.com
18/10/23 13:14:52 ** Subject: This should work
18/10/23 13:14:52 ** From: marekpatras@seznam.cz
18/10/23 13:14:52 ** 
18/10/23 13:14:52 ** Hellou mark mun
18/10/23 13:14:52 ** --- MESSAGE END ---
18/10/23 13:14:54 ** Connecting to smtp.gmail.com:587
18/10/23 13:14:54 ** Connected.
18/10/23 13:14:54 << 220 smtp.gmail.com ESMTP l11-v6sm1398703wrn.61 - gsmtp<EOL>
18/10/23 13:14:54 >> EHLO Lenovo-PC<EOL>
18/10/23 13:14:54 << 250-smtp.gmail.com at your service, [89.176.232.140]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
18/10/23 13:14:54 ** Authenticating as gazchamber.music@gmail.com
18/10/23 13:14:54 >> STARTTLS<EOL>
18/10/23 13:14:54 << 220 2.0.0 Ready to start TLS<EOL>
18/10/23 13:14:54 >> QUIT<EOL>
18/10/23 13:14:54 <<  5  1[Ď®»˘Ĺ“5Ô3p   +şňźşŚ@Î.đ<¤-ť˝dĂ”  /   ˙   #  ó ď ě †0‚‚0‚j aŚČĐ‚LÔ0
    *†H†÷
 0T10   UUS10U
Google Trust Services1%0#UGoogle Internet Authority G30
181009130800Z
190101130800Z0h10   UUS10U
California10U
Mountain View10U

Google LLC10Usmtp.gmail.com0‚"0
    *†H†÷
 ‚ 0‚
‚ ćŃ—P™Ĺ@ʸPJeJíŹK9tąLnFdÝťšl¨T]”›íĐđi1=*xpŃ?Ą_ţxŞWŇĚ#±~ÎJż‡ď›FÝ,,Ģż…ČŹçĺźxMÄžľCYP‚"eÂéJe&Ř-wVůŇB‹0Ë˝ŹŞŻKä⟍&­łS¨ tşs›Ťz÷G…ÓîĎ…Kâ‘|Â)ťfśN˘1k^'ÜŽfąVôn
—gAňŞđ«Ô†s›(ŹŃíg“ştçËYűĐIDô+;ţ`ęqńH°Ýn23ÍżĄřW$c«    —†ăo±ßť€Jn(jjá\ÄfěˇÁ Ł‚B0‚>0U%0
+0U0‚smtp.gmail.com0h+\0Z0-+0†!http://pki.goog/gsr2/GTSGIAG3.crt0)+0†http://ocsp.pki.goog/GTSGIAG30UűâíDłëüýud€\Ś“ŮÝŚ0U˙0 0U#0€w¸Pšgvv±-†Р~¦~şK0!U 00
+Öy0g01U*0(0& $ "† http://crl.pki.goog/GTSGIAG3.crl0
    *†H†÷
 ‚ ľ%Ú{Ĺ=$ń˘YEź/˝=FŢ9bžwŔ…§ˇŕăî>Ý i-¶Ó»ü$ qÍň+áhŞź«w ďü9G߸‘ ×ч
5Ř/ŻüQyG8Ä°Ř    aC$ds¶ŃćhTľĚ`3 ˘…]MĐNXe‚EfËM—´´ŽkIţ‡[])Rář~6Úgë
_D[Y0ńĂ™Ĺ=$‰ű/říř{ć§#j:Ś:ŰÚ9ţIÝŃ&¨zćµÉůÚ|Ť4“•ŢK js"¬Nf,ŇM‡Đ/|…mĎ‹ĂU ć˙“’ő™ęŢIÖ‚XÝBOIňk=ş~Ë.ö»>ł€W `0‚\0‚D 
ă©0ür8?šS0
    *†H†÷
 0L1 0UGlobalSign Root CA - R210U

GlobalSign10U
GlobalSign0
170615000042Z
211215000042Z0T10   UUS10U
Google 
18/10/23 13:14:54 << Trust Services1%0#UGoogle Internet Authority G30‚"0<CR>    *†H†÷<CR> ‚ 0‚
‚ ĘRKę˙Î$k¨ÚrhŐV]HZ-5   vZϤȱ©ţS‰ű­4˙[ź»çč Ü5su­ł±ą¤}+&yÎ@
ďQ¸ź2Ś|p†RKţj'kć6zbPŘßš‰Ě   )ëO)€Ź8€j|˝—;x}EI6OA͢ŕvW<h1ydÉn×Qfâd,yŔçeĂV„SZCmËš ŇďiŃ°ťs˘ŕ*`eP1Ďűł/ż@.µI
nÜ—úż,ź9XTŻ–čĹŽĽ¨MAĹ“‘˘ˇ‹ňţÁ$IŁGKĹݧWib+ëţ ďiű:Ąđ~)îí–÷± ä%ŕ3 Ł‚30‚/0U˙†0U%0++0U˙0˙ 0Uw¸Pšgvv±-†Р~¦~şK0U#0€›âWgŔjŢY´š-ß܆.05+)0'0%+0†http://ocsp.pki.goog/gsr202U+0)0' % #†!http://crl.pki.goog/gsr2/gsr2.crl0?U 80604g0*0(+https://pki.goog/repository/0
    *†H†÷
 ‚ ·‰–äSí»ěۨ2ź,ŁÍm­Bwł¸ćÉR` {W'Ƶ?g
™,[ZĘ"
Ýž»KH?Ź=‹!„Emő˙¬h‰ÍdâÖÖ^@ÂŽ*÷ďÓ6¤@0ő2’vű~žSęÂvü9­ţf’&éÄ8ÍIúC‡đ]ÖVM×ńÂÝ°MţĂ*n|źn\íbB™á÷6îŚ, ăF—ZwŔ ĆJý@"‡rZꜥÇZŚä¤}ą„5_‰6V@=č»5ríŻVN°».©›äű>cČ›K‘DfWŔ´–đÜ,W?R­•Ş}MĐňźś@čÖUsş<ßË [!gÂí2Ţ    
18/10/23 13:14:54 <<  F
18/10/23 13:14:54 ** Disconnected.
18/10/23 13:14:54 ** Disconnecting from smtp.gmail.com:587
18/10/23 13:14:54 ** Disconnected.
18/10/23 13:14:54 ** Disconnected.
18/10/23 13:14:54 ** Connection Closed Gracefully.

I tried nearly everything i found:

  • Disabling modem and windows firewall
  • Tried multiple ports 465,587,25
  • Tried multiple mail servers (other than gmail)
  • Changed properties of my php and sendmail files to run as administrator and have tried to run them in compatibility mode
  • When i made changes to config files i have restarted Apache
  • Tried multiple configuration file (default XAMPP with changes, creating one from scratch..) Do anyone have any clue what can cause this ? Error log changes just slightly it logs: "Connection Closed Gracefully." or "Disconnected." or both as seen in example.
  • 写回答

1条回答 默认 最新

  • dream_high1026 2018-10-23 11:37
    关注

    18/10/23 13:14:54 ** Authenticating as gazchamber.music@gmail.com

    Email Id from which account is being sent

    18/10/23 13:14:52 ** To: gazchamber.music@gmail.com

    18/10/23 13:14:52 ** From: marekpatras@seznam.cz

    You cannot use a different email id using your account credentials.

    In addition to code, this step is specially for Gmail, where you need to enable setting in order to send mails. Account setting page, make sure to enable this: enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝