One of the problems I was experiencing with my last site was the Contact Form - it uses a static subject approach.. which is fine - but the problem is if you use Gmail, then it will group emails of the same subject which isn't ideal, especially if you expect a lot of traffic that way.
On the theme I'm using there's a Subject field, but it doesn't seem to be utilized at all. When I sent my test message, I received:
EMAIL SUBJECT: .am - message from contact form
Site: .am
Name: Alex
Email: test#test.tld
Subject: .am - message from contact form
Message: Test body.
So whatever text I entered into the subject field was completely ignored, and then static text was pulled from the e-mail subject and repeated, again, in the body.
I've located the code in the respective page (I think?).
APOLLO13.PHP
if (empty($name))
$name_error = true;
if (empty($email) || !is_email($email))
$email_error = true;
if (empty($subject))
$subject_error = true;
if (empty($content))
$content_error = true;
if ($name_error == false && $email_error == false && $content_error == false && $subject_error == false) {
$subject = $site . __(' - message from contact form', TPL_SLUG);
$body = __('Site: ', TPL_SLUG) . $site . "\n\n"
. __('Name: ', TPL_SLUG) . $name . "\n\n"
. __('Email: ', TPL_SLUG) . $email . "\n\n"
. __('Subject: ', TPL_SLUG) . $subject . "\n\n"
. __('Message: ', TPL_SLUG) . $content;
$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $email\r\n";
if (wp_mail($email_to, $subject, $body, $headers)) {
$title_msg = __('Success sending form', TPL_SLUG);
} else
$title_msg = __('Something wrong. Try again!', TPL_SLUG);
} else {
$title_msg = __('Error in form', TPL_SLUG);
if (!empty($name))
$name_tag = 'value="' . $name . '"';
if (!empty($email))
$email_tag = 'value="' . $email . '"';
if (!empty($subject))
$phone_tag = 'value="' . $subject . '" title="' . __('General question ...', TPL_SLUG) . '"';
if (!empty($content))
$content_tag = $content;
}
And what I want is, essentially
EMAIL SUBJECT: $site | $subject-user-entered
Name:
Email:
Message:
How would I go about amending the code to do that? Because this:
$subject = $site . __(' - message from contact form', TPL_SLUG);
. __('Subject: ', TPL_SLUG) . $subject . "\n\n"
Seems a little pointless.
EDIT
I've found the code for the form itself if that's of any help:
<form action="http<?php echo $ssss ?>://<?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] ?>"
method="post" id="contact-form-<?php echo $form_iter ?>" class="contact-form styled-form">
<div class="submit_inputs">
<div<?php echo ($name_error ? ' class="error"' : '') ?>>
<input id="apollo13-contact-name" name="apollo13-contact-name" type="text" value=""/>
<label for="apollo13-contact-name">
<?php echo __('Name', TPL_SLUG) ?>
<span> (<?php echo __('required', TPL_SLUG) ?>)</span>
</label>
</div>
<div style="clear: both;"></div>
<div<?php echo ($name_error ? ' class="error"' : '') ?>>
<input id="apollo13-contact-email" name="apollo13-contact-email" type="text" value="" class="email"/>
<label for="apollo13-contact-email">
<?php echo __('Email', TPL_SLUG) ?>
<span> (<?php echo __('required', TPL_SLUG) ?>)</span>
</label>
</div>
<div style="clear: both;"></div>
<div<?php echo ($name_error ? ' class="error"' : '') ?>>
<input class="placeholder" id="apollo13-contact-subject" name="apollo13-contact-subject" type="text"
value=""/>
<label for="apollo13-contact-subject">
<?php echo __('Subject', TPL_SLUG) ?>
</label>
</div>
</div>
<div style="clear: both;"></div>
<div<?php echo ($name_error ? ' class="error"' : '') ?>>
<textarea id="apollo13-contact-content" name="apollo13-contact-content" rows="10" cols="40"></textarea>
</div>
<div>
<input type="hidden" name="apollo13-contact-form" value="send"/>
<input id="contact-submit" type="submit" value="<?php echo __('Submit form', TPL_SLUG) ?>"/>
</div>
</form>
I really can't say for certain as I don't know where $subject gets its original value nor do I know what your html form looks like.
$subject = $site . __(' - message from contact form', TPL_SLUG);
Would possibly change to
$subject = $site . ' | ' . $subject;
And the $body would look like the following:
$body = __('Site: ', TPL_SLUG) . $site . "\n\n"
. __('Name: ', TPL_SLUG) . $name . "\n\n"
. __('Email: ', TPL_SLUG) . $email . "\n\n"
. __('Message: ', TPL_SLUG) . $content;
Related
I have a problem that after I fill out the contact form on my HTML website I receive over 50 same E-mails. Its a HTML form connected to contact.php file which code is shown bellow. I have set everything but maybe there is a problem in my code or somewhere else.
My code is over here
<?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");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Vyplnte meno.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Vyplnte email.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Zadali ste nesprávny e-mail, skúste to znovu.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Vyplnte text správy.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "noreply#marcelaskolenia.sk";
$address = "lubosmasura#gmail.com";
$toCustomer = $email;
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Mate novu spravu od ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "Mate novu spravu od $name." . PHP_EOL . PHP_EOL;
$e_content = "\"$subject\"" . "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "Kontaktujte $name cez email, $email alebo cez mobil $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers .= 'To: Test <noreply#marcelaskolenia.sk>' . "\r\n";
$headers .= 'From: Testk <noreply#marcelaskolenia.sk>' . "\r\n";
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3 class'mark'>Sprava bola odoslana.</h3>";
echo "<p>Dakujeme <strong>$name</strong>, Vasa sprava nam bude dorucena.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
HTML code
<div class="contact_form">
<div id="message"></div>
<form id="contactform" class="row" action="contact.php" name="contactform" method="post">
<div class="col-md-12">
<input type="text" name="name" id="name" class="form-control" placeholder="Meno">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
<input type="text" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Predmet">
<textarea class="form-control" name="comments" id="comments" rows="6" placeholder="Text správy"></textarea>
<button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ</button>
</div>
</form>
</div>
</div><!-- end col -->
Any Ideas why is this happening?
Thank you.
I have a contact form on my website which calls a .php mail handler to send off the inquiries. Each time an inquiry is sent off I receive 3 copies of the email.
Any ideas what could be causing this?
The following script is in the header:
<script type="text/javascript">
$(window).load(function(){
$('#form').TMForm({
ownerEmail:'admin#endlessflooring.co.nz'
})
})
</script>
The contact form is as follows:
<form id="form">
<div class="success_wrapper">
<div class="success-message">Contact form submitted</div>
</div>
<label class="name">
<input type="text" placeholder="Name" data-constraints="#Required
#JustLetters" />
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid name.</span>
</label>
<label class="email">
<input type="text" placeholder="E-mail" data-constraints="#Required #Email" />
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid email.</span>
</label>
<label class="phone">
<input type="text" placeholder="Phone" data-constraints="#Required #JustNumbers"/>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid phone.</span>
</label>
<label class="state">
<input type="text" placeholder="City" data-constraints="#Required #JustLetters"/>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid city.</span>
</label>
<label class="message">
<textarea placeholder="Message" data-constraints='#Required #Length(min=2,max=999999)'></textarea>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*The message is too short.</span>
</label>
<div>
<div class="clear"></div>
<div class="btns">
send message</div>
</div>
</form>
And the mail handler is as follows:
<?php
//SMTP server settings
$host = "smtp.host.com";
$port = "587";
$username = "";
$password = "";
$messageBody = "";
if($_POST['name']!='false'){
$messageBody .= '<p>Name: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='false'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['phone']!='false'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['state']!='false'){
$messageBody .= '<p>Suburb: ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='false'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
if($host=="" or $username=="" or $password==""){
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$subject = 'Endless Flooring Quote Request';
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
}else{
require_once 'Mail.php';
$to = $_POST["owner_email"];
$subject = 'Endless Flooring Quote Request' . $_POST["name"];
$headers = array (
'From' => 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n",
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory(
'smtp',
array (
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $messageBody);
try{
if(PEAR::isError($mail)){
echo $mail->getMessage();
}else{
echo 'mail sent';
}
}catch(Exception $mail){
echo $mail->getMessage() ."\n";
}
}
?>
Hi I am facing a problem with my contact form I didn't receive any mails and I don't know why ..
Here is my php code is there any thing wrong
<?php
$name=$_POST ['name'];
$mobileno=$_POST ['mobileno'];
$email=$_POST ['email'];
$message=$_POST ['message'];
$to = 'any mail.com';
$subject = ' Message from your Webite';
$msg = " Your name : $name\n";
$msg .= " Your Mobile No. : $mobileno\n";
$msg .= " Your email: $email\n" ;
$msg .= " Your Message: $message";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' Thank You <br/>';
echo ' Your name ' . $name . '<br>';
echo ' Your email ' . $email . '<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
?>
<br /><br />
Here is the result from $msg: <br /><br />
<?php
echo $msg;
?>
My HTML Code I have edited the code several times but nothing happened
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="justsend.php">
<p>
<label for="mobileno">your mobile</label>
<input type="text" name="mobileno" id="mobileno">
<label for="name"><br>
your name</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">your email</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="message">your message</label>
<textarea name="message" id="message" cols="45" rows="5"></textarea>
</p>
<p>
<label for="send">send msg</label>
<input type="submit" name="send" id="send" value="Submit">
</p>
</form>
</body>
</html>
$_POST ['name']; should be $_POST['name']; remove all the spaces in your post values.
so:
$name=$_POST ['name'];
$mobileno=$_POST ['mobileno'];
$email=$_POST ['email'];
$message=$_POST ['message'];
becomes:
$name=$_POST['name'];
$mobileno=$_POST['mobileno'];
$email=$_POST['email'];
$message=$_POST['message'];
and like EternalHour said, it might be a good idea to validate if the form is filled in somehow; try this just after you declared $name and $mobileno etc;
if(!empty($name) && !empty($mobileno) && !empty($email) && !empty($message)){
// do stuff
}
the reason you would use !empty() instead of isset() is because isset would still return true if the form is submitted, since the values are set.. they are just empty.
edit:
further in your HTML change action="get" to action="post" in order to get it working.
You need to fix your $_POST variables, but I would recommend this instead so you will know if your POST succeeded.
<?php
if (isset($_POST)) {
$name=$_POST['name'];
$mobileno=$_POST['mobileno'];
$email=$_POST['email'];
$message=$_POST['message'];
$to = 'any mail.com';
$subject = ' Message from your Webite';
$msg = " Your name : $name\n";
$msg .= " Your Mobile No. : $mobileno\n";
$msg .= " Your email: $email\n" ;
$msg .= " Your Message: $message";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' Thank You <br/>';
echo ' Your name ' . $name . '<br>';
echo ' Your email ' . $email . '<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
?>
<br /><br />
Here is the result from $msg: <br /><br />
<?php
echo $msg;
} else {
echo "submit failed!";
exit;
}
?>
This way you know if there is no message your form submitted properly.
First of all, if this is on a localhost, it wont work, cause mailfunction is disabled locally, you have to run it online
Further:
I dont see really where you are going wrong, but I took over my own mail function i got on my own website and converted it to yours
if(isset($_POST['send'])){ // checks if the data from the submit button with the name send is here
$name=mysqli_real_escape_string($con,$_POST['name']);
$mobileno=mysqli_real_escape_string($con,$_POST['mobileno']);
$email=mysqli_real_escape_string($con,$_POST['email']);
$message=mysqli_real_escape_string($con,$_POST['message']);
// you had spaces between your post variables which wont work. Also if you use mysqli, its better to play safe and make them safe, in case you do also database work. The variable $con is your connection information.
// echo out if your variables working. For example:
// echo $mobileno;
// this way you know for sure if the items are set.
$message = wordwrap($message, 70); // in case its a long message, this allows 70 characters on one line
$to = 'any mail.com'; // your email
$subject = ' Message from your Webite';
$msg = " Your name : ".$name."\n";
$msg .= " Your Mobile No. : ".$mobileno."\n";
$msg .= " Your email: ".$email."\n" ;
$msg .= " Your Message:".$message ;
$headers = "MIME-Version: 1.0" . "\r\n"; // this has to do with css and html in your msg
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // this has to do with css and html in your msg
$headers .= "From: noreply#yourwebsite.com"; // change this to whatever you want it to come from
if (mail ($to, $subject, $msg, $headers)) {
echo ' Thank You <br/>';
echo ' Your name ' . $name . '<br>';
echo ' Your email ' . $email . '<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
// to make sure if your email is send it will output your message as given above, else an error
}else{
echo ' Something went wrong ... oopsie daisy';
} // closure of the if mail check
} // closure of the complete if(isset) check
dont forget to include your connection info as well for the mysqli function to sanitize your variables in case you re going to add it as well to a database. Also it's just a good practise to do it anyway. I defined $con as the connection info, yours might be different. You have to change it then to your connection variable.
if you use mysql_ functions, use mysql_real_escape_string($_POST['YourPostVariable']); without the connection info. See here. http://php.net/manual/en/function.mysql-real-escape-string.php
--edit--
updated it, because your message wouldn't output your variables, just the $name instead of the name within the $name variable.
Hope this helps, good luck debugging :)
Hi I have just modified your code just a little bit..and I have recieved the email..please check with below code..please give your email in the textbox to recieve the email
<?php
if($_POST['email'] != '')
{
$name=$_POST['name'];
$mobileno=$_POST['mobileno'];
$email=$_POST['email'];
$message=$_POST['message'];
$to = $email;
$subject = 'Message from your Webite';
$msg = " Your name : $name\n";
$msg .= " Your Mobile No. : $mobileno\n";
$msg .= " Your email: $email\n" ;
$msg .= " Your Message: $message";
mail ($to, $subject, $msg, 'From:'.$email);
echo ' Thank You <br/>';
echo ' Your name ' . $name.'<br>';
echo ' Your email ' . $email .'<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="justsend.php">
<p>
<label for="mobileno">your mobile</label>
<input type="text" name="mobileno" id="mobileno">
<label for="name"><br>
your name</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">your email</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="message">your message</label>
<textarea name="message" id="message" cols="45" rows="5"></textarea>
</p>
<p>
<label for="send">send msg</label>
<input type="submit" name="send" id="send" value="Submit">
</p>
</form>
</body>
</html>
I purchased a template from Template Monster and I can't figure out how to make the form work.
Here's the form code:
<form id="form">
<div class="success_wrapper">
<div class="success-message">Το μήνυμά σας εστάλη.</div>
</div>
<label class="name">
<input type="text" placeholder="Όνομα*:" data-constraints="#Required #JustLetters" />
<span class="empty-message">*Το πεδίο είναι υποχρεωτικό.</span>
<span class="error-message">*Το όνομα δεν είναι έγκυρο.</span>
</label>
<label class="email">
<input type="text" placeholder="Email*:" data-constraints="#Required #Email" />
<span class="empty-message">*Το πεδίο είναι υποχρεωτικό.</span>
<span class="error-message">*Το email δεν είναι έγκυρο.</span>
</label>
<label class="phone">
<input type="text" placeholder="Τηλέφωνο:" data-constraints=" #JustNumbers"/>
<span class="empty-message">*Το πεδίο είναι υποχρεωτικό.</span>
<span class="error-message">*Το τηλέφωνο δεν είναι έγκυρο.</span>
</label>
<label class="message">
<textarea placeholder="Μήνυμα:" data-constraints=' #Length(min=20,max=999999)'></textarea>
<span class="empty-message">*Το πεδίο είναι υποχρεωτικό.</span>
<span class="error-message">*Το μήνυμα είναι πολύ μικρό.</span>
</label>
<div>
<div class="clear"></div>
<div class="btns">
Καθαρισμος
Αποστολη</div>
</div>
</form>
There is also a MailHandler.php in a folder named "bat" with the following code:
<?php
//SMTP server settings
$host = "smtp.host.com";
$port = "587";
$username = "";
$password = "";
$messageBody = "";
if($_POST['name']!='false'){
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='false'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['state']!='false'){
$messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='false'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='false'){
$messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='false'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
if($host=="" or $username=="" or $password==""){
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$subject = 'A message from your site visitor ' . $_POST["name"];
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
}else{
require_once 'Mail.php';
$to = $_POST["owner_email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$headers = array (
'From' => 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n",
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory(
'smtp',
array (
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $messageBody);
try{
if(PEAR::isError($mail)){
echo $mail->getMessage();
}else{
echo 'mail sent';
}
}catch(Exception $mail){
echo $mail->getMessage() ."\n";
}
}
?>
Any help will be truly appreciated!
Ok I figured this one out... You have to get into the forms javascript file it will look like TMForms.js or something like that in the file named JS, under the very top portion of the code that looks like this
okClass:'ok'
,emptyClass:'empty'
,invalidClass:'invalid'
,successClass:'success'
,onceVerifiedClass:'once-verified'
,mailHandlerURL:'http://www.yourwebsitename.com/bat/MailHandler.php
,successShowDelay:'4000'
,stripHTML:true
MAKE SURE TO PUT THE FULL URL PATH TO THE BAT FOLDER LIKE I HAVE in bold, this will fix your issue.
Replace yourwebsite name with your actual URL and you are good to go...
You must contact the support from where your purchased the template, they can help you
Once I submit the form it will aks me this "We weren't able to send your message. Please contact site#sitenamexample.com It will not send to my WebMail. I can't figureout the problem. I really need your help guys.
$domain = "http://sitenamexample.com" . $_SERVER["HTTP_HOST"];
$siteName ="My Website name";
$siteEmail = "site#sitenamexample.com";
$er = "";
if(isset($_POST["contactEmail"])){
global $subject, $message;
$contactName = htmlentities(substr($_POST["contactName"], 0, 100), ENT_QUOTES);
$contactEmail = htmlentities(substr($_POST["contactEmail"], 0, 100), ENT_QUOTES);
$messageSubject = htmlentities(substr($_POST["messageSubject"], 0, 100), ENT_QUOTES);
$messageContent = htmlentities(substr($_POST["messageContent"], 0, 100), ENT_QUOTES);
if (!preg_match('/' . '^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]{2,})+$' . '/'
, $contactEmail))
{
$er .= 'Please enter a valid e-mail address.<br>';
}
if ($contactName == "" || $contactEmail == "" || $messageSubject == "" ||
$messageContent == ""){
$er .= 'Your Name, E-mail, Message Subject, and Message Content cannot be left
blank.<br />';
}
if($er == ''){
$subject = $messageSubject;
$message =
'<html>
<head>
<title>' . $siteName . ': A Contact Message </title>
.<body>
' . wordwrap($messageContent, 100) . '
</body>
</html>';
}
$to = $siteName . ' Contact Form <' . $siteEmail . '>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=is0-8859-1' . "\r\n";
$headers .= 'From: ' . $contactName . ' <' . $contactEmail . '>' ."\r\n";
$headers .= 'Reply-To: ' . $contactName . ' <' . $contactEmail . '>' . "\r\n";
$headers .= 'Return-Path: ' . $contactName . ' <' . $contactEmail . '>' . "\r\n";
$headers .= 'X-Mailer: ' . $siteName . "\r\n";
if (mail($to, $subject, $message, $headers)){
echo '<div>Thank you for contacting ' . $siteName . '. We will read your message and
contact you if necessary.</div>';
}
else {
$er .= 'We weren\'t able to send your message. Please contact ' . $siteEmail .
'.<br />';
}
}
else {
showContactForm();
}
if ($er != '' && isset($_POST["contactEmail"])){
showContactForm($contactName, $contactEmail, $messageSubject, $messageContent, $er);
}
else if($er != '' && !isset($_POST["contactEmail"])){
showContactForm('', '', '', $er);
}
function showContactForm($contactName = "", $contactEmail = "", $messageSubject = "",
$messageContent = "", $er = ''){
echo '<div style="font-weight:bold; margin: 5px 0; "> ' . $er . '</div>
<div id="email_form">
<h1> Contact Form</h1>
<form method="post" name="contact" action="#contactus">
<label for="name">Name:</label>
<input type="text" id="author" name="contactName" class="input_field" />
<div class="cleaner h10"></div>
<label for="email" class="adjust">Email:</label>
<input type="text" id="email" name="contactEmail" class="input_field" />
<div class="cleaner h10"></div>
<label for="messageSubject" class="adjust">Subject:</label>
<input type="text" id="messageSubject" name="messageSubject" class="input_field" />
<div class="cleaner h10"></div>
<label for="text" class="adjust">Comments:</label>
<textarea id="text" name="messageContent" rows="0" cols="0"></textarea>
<div class="cleaner h10"></div>
<input type="submit" class="submit_btn float_l" name="submitButton" id="submit"
value="Send Message" />
<input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" />
</form>
<div class="clearfix"></div>
</div>';
}
?>
<div class="clearfix"></div>
<?php include ("includes/footer.php"); ?>
You're code is generally correct (but remember - $to should only be the email address without any < or >). I think the reason of your problem is disabled Sendmail PHP Library - you can enable it in server settings or if you have not access to it - read about phpmailer.