I have a website. i want to get form details from my customer... i am preparing some code. The code works good on some hosting panel but not working in my hosting panel. i think some functions are not supporting my hosting. i report the hosting provider but there is no good solution. can any one solve this... Thanks in advance
my advertisement.html form is looking like this
<form action="advertisement-form.php" method="post" class="comment-form row-fluid" data-validate="parsley">
<p>
<label for="name" class="span2">Your Name</label>
<input type="text" class="span10" placeholder="Your Name" id="name" name="name" required >
</p>
<p>
<label for="email" class="span2">E-mail</label>
<input type="email" class="span10" placeholder="Your E-mail" id="email" name="email" required >
</p>
<p>
<label for="name" class="span2">Your Ad Title</label>
<input type="text" class="span10" placeholder="Ad Title" id="ad_title" name="ad_title" required >
</p>
<p>
<label for="site" class="span2">Target URL</label>
<input type="text" name="target_url" id="target_url" class="span10" data-type="url" required>
</p>
<p>
<label for="site" class="span2">Banner URL</label>
<input type="text" name="banner_url" id="banner_url" class="span10" data-type="url" required>
</p>
<p>
<label for="site" class="span2">Payment Email</label>
<input type="text" name="payment_email" id="payment_email" class="span10" data-type="url" required>
</p>
<p>
<label for="mess" class="span2">Message</label>
<textarea name="message" class="span10" data-trigger="keyup" data-rangelength="[20,1000]"></textarea>
</p>
<p>
<input type="submit" value="Continue" class="button button-load large-button offset2 span4">
</p>
</form>
and my form processing is looking like this, named with advertisement-form.php
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "myemail@gmail.com";
$email_subject = "New Advertisement for Website";
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['ad_title']) ||
!isset($_POST['target_url']) ||
!isset($_POST['banner_url']) ||
!isset($_POST['payment_email']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$ad_title = $_POST['ad_title']; // required
$target_url = $_POST['target_url']; // required
$banner_url = $_POST['banner_url']; // required
$payment_email = $_POST['payment_email']; // not required
$message = $_POST['message']; // required
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Ad Title: ".clean_string($ad_title)."\n";
$email_message .= "Target URL: ".clean_string($target_url)."\n";
$email_message .= "Banner URL: ".clean_string($banner_url)."\n";
$email_message .= "Payment Email: ".clean_string($payment_email)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
when a user fill the form he got success message. but i am not receiving confirmation mail. this script working some hosting panels, not in my hosting panel.can any one solve this...
Thank you once again.
I will suggest this as a try, ending each line with \\r\\n
and also adding a To header (redundant as it might seem). Also, declaring charset=utf-8
in the header should be enough.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
// Additional headers
// This might look redundant but some services REALLY favor it being there.
$headers .= "To: $to_fullname <$to_email>\r\n";
$headers .= "From: $from_fullname <$from_email>\r\n";
Also the function is die
not died
1 - change
died('We are sorry, but there appears to be a problem with the form you submitted.');
to
die('We are sorry, but there appears to be a problem with the form you submitted.');
2- remove @ before mail function. As using @ before any statement will suppress errors if anything goes wrong. So if you remove this.. It would be easy to troubleshoot. Follow the 2 steps above and try again. If you see any error, paste them here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.