hcccs Posted April 4, 2022 Share Posted April 4, 2022 I'm trying to send a simple PHP mail from my web page but there is something wrong of course. php.ini [mail function] ; For Win32 only. ; https://php.net/smtp SMTP = send.one.com ; https://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; https://php.net/sendmail-from sendmail_from = hans@strahle.eu Web page <!DOCTYPE html> <html lang="en"> <head> <title>Email test</title> <meta charset="utf-8" /> </head> <body> <h1>Email test</h1> <h2>Testing PHP email</h2> <br><br> <h3></h3> <?php $to = "hans@strahle.eu"; $subject = "Email test"; $message = "This is an email test"; if (mail($to, $subject, $message)) { echo "Email sent"; } else { echo "Email failed"; } echo 'email processed'; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/314662-sending-php-mail-from-web-page/ Share on other sites More sharing options...
requinix Posted April 4, 2022 Share Posted April 4, 2022 mail() is easy to use but not very good at what it tries to do. Consider using something like PHPMailer or Switft Mailer instead. Quote Link to comment https://forums.phpfreaks.com/topic/314662-sending-php-mail-from-web-page/#findComment-1594869 Share on other sites More sharing options...
ginerjm Posted April 4, 2022 Share Posted April 4, 2022 Doesn't the manual mention the addition of the header argument? Quote Link to comment https://forums.phpfreaks.com/topic/314662-sending-php-mail-from-web-page/#findComment-1594871 Share on other sites More sharing options...
gizmola Posted April 5, 2022 Share Posted April 5, 2022 I don't know if you have additional configuration you aren't showing us, but the mail server has to be configured to relay mail from your server. Outside of that, there are so many different things that could be causing the send to fail. Are you getting an Email failed message? As requinix stated, there is little to no visibility into SMTP using the mail() function in the way you are trying to use it. Phpmailer or Symfony mailer have ways to actually debug the internals of the SMTP process. Quote Link to comment https://forums.phpfreaks.com/topic/314662-sending-php-mail-from-web-page/#findComment-1594876 Share on other sites More sharing options...
maxxd Posted April 5, 2022 Share Posted April 5, 2022 Highly recommend PHPMailer instead of native PHP mail(). It's much easier to use and offers robust debugging when you run into problems. I don't have direct experience (mostly because I haven't used native mail() in a long time) but PHPMailer is apparently more reliable as well. Quote Link to comment https://forums.phpfreaks.com/topic/314662-sending-php-mail-from-web-page/#findComment-1594877 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.