I have a site up and running and cant seem to get the php to send the form data. Get thank you message sometimes but never appears in mail. my aim is to have the form collect the data then email the data to the client.
Thanks for any help. I am struggling to get to grips with php it would appear.
<?php
$to = "********#*******.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['enquiry'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully";}
else
{print "We encountered anerror sending your mail";}
?>
<section class="container">
<section class="col-lg-6 col-lg-offset-1">
<form class="form-horizontal text-center" role="form" method="post" action="form_send.php">
<div class="form-group">
<label for="Name" class="col-lg-2 control-label">Name:</label>
<div class="col-lg-6">
<input type="name" class="form-control" id="name" name="name" placeholder="Enter Name...">
</div>
</div>
<div class="form-group">
<label for="Email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-6">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email...">
</div>
</div>
<div class="form-group">
<label for="Phone" class="col-lg-2 control-label">Phone:</label>
<div class="col-lg-6">
<input type="phone" class="form-control" id="phone" placeholder="Enter Phone Number...">
</div>
</div>
<div class="form-group">
<label for="Enquiry" class="col-lg-2 control-label">Enquiry:</label>
<div class="col-lg-6">
<textarea type="enquiry" class="form-control" rows="5" id="enquiry" name="enquiry" placeholder="Enter Email..."></textarea>
</div>
</div>
<div class="form-group">
<label for="Enquiry" class="col-lg-2 control-label"></label>
<div class="col-lg-6">
<button class="btn btn-primary" type="submit">Send Message</button>
</div>
</div>
</form>
Reply from email server:
Technical details of permanent failure: Google tried to deliver your message, but it was rejected by the server for the recipient domain peoplespropertyshop.co.uk by aspmx.l.google.com. [2607:f8b0:4003:c02::1a]. The error that the other server returned was: 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1 support.google.com/mail/bin/answer.py?answer=6596 t6si822722oei.44 - gsmtp
First you should check that your code is in one file (form_send.php). After that add some check if user have submitted the form:
if (!empty($_POST))
Message is sent to $to email. If you want to change that, pass $email paramter to mail() function:
$sent = mail($to, $subject, $message, $headers) ;
to:
$sent = mail($email, $subject, $message, $headers);
Also check your mail server configuration and add some validation.
$email = htmlentities($_REQUEST['email']);
$message = htmlentities($_REQUEST['enquiry']);
Related
I never used PHP before, but I need to set up an HTML form from to be sent from my website to my gmail account. Checked some tutorials and came up with this code. But for some reason it is not working. When I hit submit it goes to a "Page Not Found
Looks like you've followed a broken link or entered a URL that doesn't exist on this site." Not sure what am I doing wrong.
I have my HTML document, and I have my PHP document. Saved together.
<form action="contact.php" method="POST" name="form">
<div class="row">
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="name">Please enter your name:</label>
<input name="name" type="text" class="form-control" placeholder="Harry Potter">
</div>
</div>
<div class="col-12 col-md-6">
<div class="contact-form">
<label for="mail">Your email address:</label>
<input name="mail" type="email" class="form-control" placeholder="harry#potter.com">
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="contact-form">
<label for="message">How can I help you?</label>
<textarea name="message" class="form-control" id="form-text" cols="30" rows="10" placeholder="Let's do some magic"></textarea>
</div>
</div>
</div>
<div id="submit" class="text-center">
<button name="submit" type="submit" class="btn mt-5 mx-auto">Submit</button>
</div>
</form>
<?php
if(isset($_POST["submit"])) {
$name=$_POST["name"];
$mailFrom=$_POST["mail"];
$message=$_POST["message"];
$mailTo = "myaddress#gmail.com";
$subject = "Form from my website";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name."\n\n".$message;
if(mail($mailTo, $subject, $txt, $headers)) {
echo "<h1>I recieved your email! Will be in touch with you soon.</h1>";
}
else{
echo "<h1>Something went wrong! Try again.</h1>";
}
header("Location: https://www.whatever.com");
}
?>
I want to send email from the contact form on my site that has multiple form fields. But I can't seem to get that right.
Here is my form HTML code:
<form class="form-horizontal" action="mail.php" method="post">
<h2>Quick Contact</h2>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Full Name:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="fname" placeholder="Enter Full Name" name="fname">
</div>
</div><br>
<div class="form-group">
<label class="control-label col-sm-2" for="num">ID Number:</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="num" placeholder="Enter ID Number" name="id">
</div>
</div><br>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-6">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address" name="email">
</div>
</div><br>
<div class="form-group">
<label class="control-label col-sm-2" for="sal">Monthly Salary:</label>
<div class="col-sm-6">
<input type="number" class="form-control" id="sal" placeholder="Enter Salary" name="salary">
<div class="label label-warning" >Numbers only. Any other characters are not permitted.</div>
</div>
</div><br>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-danger">Submit</button>
</div>
</div>
</form>
This is my PHP code, I am using PHP mail() to send the email:
<?php
$to = 'mail#gmail.com';
$subject = 'Loan Request';
$from = $_POST['email']; // required
$name = $_POST['fname']; // required
$id = $_POST['id']; // required
$telephone = $_POST['mobile']; // not required
$salary = $_POST['salary']; // required
$message = $name." ".$telephone." ".$salary;
$headers = 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" ;
// Sending email
if(mail($to, $subject, $from, $message)){
header('Location: http://example.com');
} else{
echo 'Unable to send email. Please try again.';
}
?>
The mail delivers quite alright, but does not display the entire form details when it enters my email. I will like to know how I can capture all the form fields cos I intend to add more form fields. It's a really long form.
If you are using PHP's mail function then the parameters should be in this order. In your example the $headers parameter was not passed at all.
if (mail($to, $subject, $message, $headers)) {
header('Location: http://example.com');
} else {
echo 'Unable to send email. Please try again.';
}
first ensure ur localhost/server is configured to send email
use the following function to send email (works for me)
public function email($to,$cc,$from,$subject,$message){
$config['protocol']='mail';
$config['smtp_host']='ssl://smtp.gmail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='urEmail#gmail.com';
$config['smtp_pass']='urPassword';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->load->library('email',$config);
// $this->email->initialize($config);
$this->email->from($from, 'Limecar.in');
$this->email->to($to);
$this->email->cc($cc);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {return true;}
else {return false;}
}
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 5 years ago.
i am facing a problem in contact form it gets validated successfully and i get the Jquery response " your email has been sent successfully" but the problem is the email dosen't get delivered. i am pasting the code here please help me. its an html based site but.
CONTACT FORM.HTML
<!-- contact-area start -->
<div class="contact-area ptb-120 bg-2">
<div class="container">
<div class="row">
<div class="col-md-4 col-xs-12">
<div class="contact-wrap">
<h3>CONTACT INFO</h3>
<p>#123 King , Melbourne vic 3000, Sydney New City, Australia</p>
<p>(+08) 9673 123 765,(+08) 9673 148 112</p>
<p>hello#university.com</p>
</div>
</div>
<div class="col-md-8 col-xs-12">
<div class="contact-form">
<div class="cf-msg"></div>
<form action="mail.php" method="post" id="cf">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" placeholder="Name" id="fname" name="fname">
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" placeholder="Email" id="email" name="email">
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<input type="text" placeholder="Subject" id="subject" name="subject">
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<textarea class="contact-textarea" placeholder="Message" id="msg"
name="msg"></textarea>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<button id="submit" class="cont-submit btn-contact" name="submit">Submit
A Message</button>
</div>
</div>
</form>
MAIL.PHP
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//Taking all values
$to = "shijumax#gmail.com";
$fname = $_POST['fname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['msg'];
$output = "Name: ".$fname."\n\nSubject: ".$subject."\n\nMessage:
".$msg;
$headers = 'FROM: "'.$email.'"';
$send = mail($to, $fname, $output."\n\n***This message has been
sent from me", $headers);
$body = "Name: ".$fname."\n E-Mail: $email\n Message:\n $msg";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
}
?>
Im not receiving emails from my email form.
I created a simple form that takes 4 fields and sends them to our emails. I tested my php code with no errors. I double checked the html to see if the script was referring properly which it was. I believe that the ids and names are correct. I also triple checked the variables I created on the php code. I've googled everything I could come up with no luck. Thanks!
var dump $body shows
Thank you! One of our station representatives will contact you soon.
string(119) "
Name: TEST
Email: test#emaol.com
Station: 1234
Message:
I need help with.
FORM
<form class="form-horizontal" role="form" method="post" action="feedback.php">
<fieldset>
<!-- Form Name -->
<legend>Our team will reach out to you as soon as possible.</legend>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Full Name</label>
<div class="controls">
<input id="name" name="name" placeholder="John Doe" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">E-Mail</label>
<div class="controls">
<input id="email" name="email" placeholder="affiliate.marketing.app#123.com" class="input-xlarge" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group col-xs-4">
<label class="control-label" for="textinput">Station Code</label>
<div class="controls">
<input id="station" name="station" placeholder="xxx" class="input-xlarge" type="text">
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="textarea">Message</label>
<div class="controls">
<textarea id="message" name="message">I need help with....</textarea>
</div>
</div>
<!-- Button -->
<div class="control-group">
<label class="control-label" for="submit"></label>
<div class="controls">
<button type="submit" id="submit" value="Send" name="singlebutton" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
PHP PAGE
<?php
/* These are the variable that tell the subject of the email and where the email will be sent.*/
$emailSubject = 'Station App Support Request';
$mailto = 'myemail#domain.com, myemail2#domain.com';
/* These will gather what the user has typed into the fieled. */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$stationField = $_POST['station'];
$messageField = $_POST['message'];
/* This takes the information and lines it up the way you want it to be sent in the email. */
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Station: $stationField <br>
Message: $messageField <br>
EOD;
$headers = "From: $emailField\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.
?>
I'm working on a contact form currently and it appears to be going through, but I'm not getting the email.I unsure of what the problem is. I'm guessing it's in my PHP, but I don't see where the problem is.
HTML Markup:
<form method="post" id="contact" class="peThemeContactForm" action="mail.php">
<div id="personal" class="bay form-horizontal">
<div class="control-group"><!--name field-->
<div class="controls">
<input class="required span9" type="text" name="author" data-fieldid="0" value="Full Name" onclick="if(this.value=='Full Name') this.value=''" onblur="if(this.value=='') this.value='Full Name'">
</div>
</div>
<div class="control-group"><!--email field-->
<div class="controls">
<input class="required span9" type="email" name="email" data-fieldid="1" value="Your Email" onclick="if(this.value=='Your Email') this.value=''" onblur="if(this.value=='') this.value='Your Email'">
</div>
</div>
<div class="control-group"><!--message field-->
<div class="controls">
<textarea name="message" rows="12" class="required span9" data-fieldid="2" onclick="if(this.value=='Type Message') this.value=''" onblur="if(this.value=='') this.value='Type Message'">Type Message</textarea>
</div>
</div>
<div class="control-group">
<div class="controls send-btn">
<button type="submit" class="contour-btn red">Send Message</button>
</div>
</div>
</div>
<div class="notifications">
<div id="contactFormSent" class="formSent alert alert-success">
<strong>Your Message Has Been Sent!</strong> Thank you for contacting us.</div>
<div id="contactFormError" class="formError alert alert-error">
<strong>Oops, An error has ocurred!</strong> See the marked fields above to fix the errors.</div>
</div>
</form>
PHP:
<?php
if(isset($_POST['email'])){
$mailTo = "jake_ols#live.com";
$subject = "mail from web";
$body = "New message from web
<br><br>
FROM: ".$_POST['email']."<br>
NAME: ".$_POST['author']."<br>
COMMENTS: ".$_POST['message']."<br>";
$headers = "To: Jake <".$mailTo.">\r\n";
$headers .= "From: ".$_POST['author']." <".$_POST['email'].">\r\n";
$headers .= "Content-Type: text/html";
//envio destinatario
$mail_success = mail($mailTo, utf8_decode($subject), utf8_decode($body), $headers);
}
?>
You most likely answer is that the server does not have mail enabled
Use phpinfo() to find which ini file you should be editing and make sure that you php server is set up to send mail.
; For Win32 only.
sendmail_from = me#example.com
Alternatively use SMTP and connect to a service like Mailgun https://documentation.mailgun.com/quickstart-sending.html#send-via-smtp