• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 884
  • Last Modified:

PHP - mail button not working, HTML5 website

Hello - I have an HTML5 website and need help getting the mail.php to work. My web host is Brinkster, and I've verified that PHP is running.

Here's the current code:
<?php
  
  $to = "user@mydomain.com";
  
  $name = $_POST['name'];
  $subject = "Email from webform";
  
  $body = stripslashes($_POST['message']);
  
  $from = $_POST['email'];
  $headers = "From: " . $from;
  $error_messages = array();
  
  if( strlen($name) < 1 ) {
    $error_messages[] = "name required";
  }
  
  if( strlen($body) < 1 ) {
    $error_messages[] = "comment required";
  }
  
  if( strlen($from) < 1 ) {
    $error_messages[] = "email required";
  }
  
  if(sizeof($error_messages) == 0 && mail($to, $subject, $body, $headers)) {
    echo("thank you");
  } else {
    foreach( $error_messages as $error_message ) {
      echo "$error_message <br />";
    }
  }
  
?>

Open in new window


Any help appreciated. Thanks
0
Trevor Local
Asked:
Trevor Local
  • 13
  • 4
  • 4
  • +3
2 Solutions
 
Loganathan NatarajanLAMP DeveloperCommented:
do you get any error message?
0
 
Trevor LocalAuthor Commented:
No - there's no response, and no reaction from the "send" button.
0
 
Dave BaldwinFixer of ProblemsCommented:
There's not really anything there, at least not adequate to send email.  Here is my PHP Email demo that I have posted here many times.  Save it as "Email.php" so it can POST to itself.  Enter your own email address in the $toText and try it out.

<?php
error_reporting(E_ALL);
ini_set('display_errors','1');

# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
    $announce="---";
}
else {
	if($fromText === "") die("No name!");
  $toText="youremail@yourdomain.com";
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "From: ".$fromText."\r\n";
//	$header .= "Cc: ".$ccText."\n";
	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "Return-Path : ".$fromText."\r\n";
	$header .= "X-Mailer: PHP\r\n";
	$header .= "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//	ini_set(sendmail_from,$fromText);  
	mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
//	ini_restore(sendmail_from);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
<!-- 
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
-->
</style>
<script type="text/javascript">
<!--
function check()
{
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    {
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    submitOK="false"
    //return false;
    }
if (nam.length < 3)
    {
    alerttxt=alerttxt+"Please enter your name.\r\n";
    submitOK="false"
    //return false;
    }
if (submitOK=="false")
    {
    alert(alerttxt);
    return false;
    }

}
// -->
</script>
</head>

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

<?php
if ($send != "") {
   	echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);
		}
?>

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<form method="POST" action="Email.php" onsubmit="return check();">
    <p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail">
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  </form>
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>

</font>
</td></tr>
</table> 
</div>

</body>
</html>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Loganathan NatarajanLAMP DeveloperCommented:
please post your html code, with button click
0
 
Trevor LocalAuthor Commented:
I uploaded the email.php, tested it, and I get some error code as well as "Your Message Has Been Sent", however the message was not sent.

Here's the output:
Warning: mail() [function.mail]: Could not execute mail delivery program '/usr/sbin/sendmail -t -i' in /sites/hostserver/mydomainserver/home/public_html/email.php on line 33
To: webform@mydomain.com
Subject: Web Mail
testing webform
From: validuser@gmail.com Reply-To : validuser@gmail.com Return-Path : validuser@gmail.com X-Mailer: PHP MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
Is this a Windows server?  That error message usually occurs because you do not have a local SMTP server installed to send out email.  Do you have access to your 'php.ini' file?
0
 
Trevor LocalAuthor Commented:
Here's a copy of the HTML button click:

<div class='mod modGetInTouch'>
            <h4>(xxx) xxx-8515</h4>
            <p class='thanks' style='display: none'>
              Thanks for contacting us. We'll be in touch soon!
            </p>
            <form class="nice" method="post" action="send.php" accept-charset="UTF-8"><p>
              <input class="input-text required" placeholder="Your Name" name="name" type="text" />
            </p>
            <p>
              <input class="input-text required email" placeholder="Your Email" name="email" type="text" />
            </p>
            <p>
              <textarea class="required" placeholder="Your Message" name="message" rows="" cols=""></textarea>
            </p>
            <p>
              <input class="button" value="Send" type="submit" />
            </p>
            </form>
          </div>

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
This page https://help.brinkster.com/KB/a9/unable-to-send-email-with-wordpress.aspx gives the settings that you need for sending email.  They're talking about Wordpress but the settings for SMTP host and SMTP port are going to be the same.
0
 
Trevor LocalAuthor Commented:
It's a Linux host, and I don't see the php.ini file.
0
 
Dave BaldwinFixer of ProblemsCommented:
You need to call your hosting company and ask them what you need to do.  Most Linux hosts provide 'sendmail' or the equivalent and this wouldn't be a problem.  It appears that Brinkster has set things up differently.  In that case, only they can change it.  That link above is the only thing I found in their help pages about email setup.
0
 
Ray PaseurCommented:
This test script, shown below in its entirety, should work.  Install it in your web root directory.  You will want to give the tech support team at Brinkster something to test the installation and this will do the trick.  Change the "to" address to your own email.  You may have to look in the spam folder to find the message.  Once you know this part is working and you have received the Hello World message, you can move on to adding other headers, etc.

<?php error_reporting(E_ALL);
ini_set('display_errors', TRUE);
mail('You@Your.org', 'PHP mail() test', 'Hello World');

Open in new window

0
 
Chris SandriniSenior System EngineerCommented:
Hi

If php is not able to send the email it will not print any errors. Try to change your mailfunction to

mail($to, $subject, $body, $headers,'-f' . $from)

Open in new window


You can also check if you are able to send an email from shell with

echo "test" | mail -s test your@mail.com

Open in new window

0
 
Trevor LocalAuthor Commented:
I contacted Brinkster and they do not support PHP mail, but do support PHPmailer. They gave me this link:
Brinkster - PHPmailer info

So I'll see if I can insert relevant information to get it to work.
0
 
Trevor LocalAuthor Commented:
OK I set up the new phpmailer form and I can use the web mail form to send a message, but it's not passing the input information (user name, email address, message contents) nor is it giving any response, like "thanks for the message".
0
 
Trevor LocalAuthor Commented:
I used the sample code and it works. Not sure how to pass along the information from the web form: email address, user name, message.

Code I'm using:
<?PHP
 
require("/sites/servername/username/home/includes/class.phpmailer.php");
 
$mail = new PHPMailer();
 
$mail->IsSMTP();
$mail->Host = "mymail.brinkster.com";
$mail->SMTPAuth = true;
$mail->Username = "you@domain.com";
$mail->Password = "password";
 
$mail->From = "you@domain.com";
$mail->FromName = "Your Name";
$mail->AddAddress("user@domain.com", "Display Name");
 
$mail->IsHTML(true);
 
$mail->Subject = "Test message sent using the PHPMailer component";
$mail->Body    = "This is a test message.";
 
if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
 
echo "Message has been sent";
?>

Open in new window

0
 
Trevor LocalAuthor Commented:
Anyone have pointers on how to pass web form info via the phpmailer script?
thanks!
0
 
Kyle HamiltonData ScientistCommented:
use method POST in your form. then get the values from the "email", "name", and "message" fields:

a start:

<?PHP
 
require("/sites/servername/username/home/includes/class.phpmailer.php");
 
$mail = new PHPMailer();
 
$email = $_POST["email"];
$name = $_POST["name"];
$message = $_POST["message"];

$mail->IsSMTP();
$mail->Host = "mymail.brinkster.com";
$mail->SMTPAuth = true;
$mail->Username = "you@domain.com";
$mail->Password = "password";
 
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress("user@domain.com", "Display Name");
 
$mail->IsHTML(true);
 
$mail->Subject = "Test message sent using the PHPMailer component";
$mail->Body    = $message;
 
if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
 
echo "Message has been sent";
?>

Open in new window

0
 
Ray PaseurCommented:
This shows the general design of how to use HTML forms in PHP.
http://us.php.net/manual/en/tutorial.forms.php
0
 
Trevor LocalAuthor Commented:
Hi kozaiwaniec - I got the code and inserted my values and now the mailer works. Thank you!
But I do not get any verification or feedback from the web button.
0
 
Kyle HamiltonData ScientistCommented:
do you mean the submit button?

you would need to redirect the browser to a thank you page in your script.

Or,

You can use AJAX to submit the form and display a thank you message upon success.

which way do you want to do it?
0
 
Trevor LocalAuthor Commented:
It sounds like the AJAX way is more clean and doesn't need to use a redirect, is that correct?
0
 
Ray PaseurCommented:
I would recommend hiring a PHP professional programmer to help with this project.  It's not "hard" but there are so many layers of knowledge that trying to acquire them all for yourself may take a long time.  And in being respectful of your time, a pro can give you the solutions immediately, whereas you might be spending weeks or months of study trying to acquire knowledge that some else has and can implement in a matter of hours.

If you decide that learning is more important than instant results (a very understandable choice) then grab a copy of this book and dive in.   It's very readable and comes with a downloadable code library that you can copy and modify for your own tasks.
http://www.sitepoint.com/books/phpmysql5/

Best regards, ~Ray
0
 
Trevor LocalAuthor Commented:
OK, I figured out the missing code. I changed
echo "Message has been sent";

Open in new window

to
echo "success";

Open in new window

0
 
Ray PaseurCommented:
You're kidding, right?
0
 
Kyle HamiltonData ScientistCommented:
:o
0
 
Trevor LocalAuthor Commented:
Why would I be kidding?
0
 
Trevor LocalAuthor Commented:
Thanks for the help everyone!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 13
  • 4
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now