0

I Followed a simple tutorial from mmtuts on YouTube and uploaded my html and php to my website at dougcannonbio.com, my website that I'm trying to make. Just starting out with a template before I put out any details to make sure that they all function.

Everything is looking great so far and now I'm having trouble just even trying to send anything from this text box to my email. Is this too much to ask for. What am I doing wrong? Am I missing something?

I'm just trying send to my email through this simple contact form using nothing but php.

HTML

   <div class="form">      
    <input name="name" type="text" class="feedback-input" placeholder="Name" />   
    <input name="email" type="text" class="feedback-input" placeholder="Email" />
    <input name="subject" type="text" class="feedback-input" placeholder="Subject" />
    <textarea name="text" class="feedback-input" placeholder="Comment"></textarea>
    <input type="submit" value="SUBMIT"/>
   </div>

CSS

form { max-width:420px; margin:50px auto; }

.feedback-input {
  color:white;
  font-family: Helvetica, Arial, sans-serif;
  font-weight:500;
  font-size: 18px;
  border-radius: 5px;
  line-height: 22px;
  background-color: transparent;
  border:2px solid #CC6666;
  transition: all 0.3s;
  padding: 13px;
  margin-bottom: 15px;
  width:100%;
  box-sizing: border-box;
  outline:0;
}

.feedback-input:focus { border:2px solid #CC4949; }

textarea {
  height: 150px;
  line-height: 150%;
  resize:vertical;
}

[type="submit"] {
  font-family: 'Montserrat', Arial, Helvetica, sans-serif;
  width: 100%;
  background:#CC6666;
  border-radius:5px;
  border:0;
  cursor:pointer;
  color:white;
  font-size:24px;
  padding-top:10px;
  padding-bottom:10px;
  transition: all 0.3s;
  margin-top:-4px;
  font-weight:700;
}
[type="submit"]:hover { background:#CC4949; }

/* End contact form styling */

PHP

<?php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $comment = $_POST['text'];

    $mailTo = "contact@dougcannonbio.com";
    $headers = "From: ".$email;
    $comment = "You have received an email from ".$name.".\n\n".$comment;

    mail($mailTo, $subject, $txt, $headers);
    header("Location: index.php?mailsend");
}
Azazel
  • 573
  • 3
  • 10
  • 23
  • 3
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – BhAvik Gajjar Dec 11 '19 at 08:29
  • with this html you are not sending anything because is missing form and form action in php if you try print_r($_POST); will be empty – Ivan Dec 11 '19 at 08:30

1 Answers1

0

<?php


if(!$_POST) exit;

// Email address verification, do not edit.
function isEmail($email) {
 return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}

if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

$first_name     = $_POST['first_name'];
$last_name     = $_POST['last_name'];
$email    = $_POST['email'];
$phone   = $_POST['phone'];
$select_price   = $_POST['select_price'];
$select_service   = $_POST['select_service'];
$subject  = $_POST['subject'];
$comments = $_POST['comments'];
$verify   = $_POST['verify'];


if(trim($first_name) == '') {
 echo '<div class="error_message">Attention! You must enter your name.</div>';
 exit();
}  else if(trim($email) == '') {
 echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
 exit();
} else if(!isEmail($email)) {
 echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
 exit();
}

if(trim($comments) == '') {
 echo '<div class="error_message">Attention! Please enter your message.</div>';
 exit();
}

if(get_magic_quotes_gpc()) {
 $comments = stripslashes($comments);
}



$address="arumugambecse@gmail.com";
  $headers="MIME-Version: 1.0" . "\r\n";
  $headers.="Content-type:text/html;charset=UTF-8" . "\r\n";
  $headers.="From: $email \r\n";
  $headers.="X-Priority: 1\r\n";
  $headers .= "Reply-To: $email";
  //$headers .= "Bcc: $emailList\r\n";

  $subject= $select_service;
  $message = 'test message';
        

 if(mail($address,$subject,$message,$headers))
 {

 // Email has sent successfully, echo a success page.

 echo "<fieldset>";
 echo "<div id='success_page'>";
 echo "<h1>Email Sent Successfully.</h1>";
 echo "<p>Thank you <strong>$first_name</strong>, your message has been submitted to us.</p>";
 echo "</div>";
 echo "</fieldset>";

} else {

 echo 'ERROR!';

}
?>