Jump to content

Sending PHP mail from web page


hcccs

Recommended Posts

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>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.