Capture an email using PHP [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I have created a simple php file to capture emails from users who are signing up for a newsletter. The 'captured email' is not getting sent through to me. The email I receive is this 'Email: ' without the users email.
<?php
session_start();
//require_once('recaptchalib.php');
$privatekey = "6Ldni7wUAAAAAIMRGmqhTeehXqkx0ZC";
$publickey = "6Ldni7wUAAAAAKO37aO2hfy3kHyXTuN";
$email = $_POST['email'];
$admin_email = 'example#email.com';
$email_from = 'example#email.com';
$email_subject = "Newsletter Signup";
$email_body = "Email: $email \r\n";
$to = "$admin_email";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: thankyou.html");
?>
HTML
<form method="POST" action="newsletter.php">
<input type="text" name="newsletter" title="" placeholder="Email Address..." required>
<button type="submit">Sign Up</button>
<div class="clearboth"></div>
<div class="g-recaptcha" data-sitekey="6Ldni7wUAAAAAKO37aO2hfy3kHyXTuN"></div>
<label><input name="consent" type="checkbox" class="input-name" required>
<span class="captchaspan obligatorycheck"><!--Some text--></span>
</label>
</form>

$email_body = "Email: $contact \r\n";
You have never defined $contact.

Related

PHP contact form configuration [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 10 months ago.
Hi guys I run my website and it all work except contact us form.
HTML
<div class="border"></div>
<form class="contact-form" action="mail.php" method="post">
<div class="fisrtthree">
<input type="text" name="fname" class="contact-form-text" placeholder="First name" required>
</div>
<div class="fisrtthree">
<input type="text" name="lname" class="contact-form-text" placeholder="Last name" required>
</div>
<div class="fisrtthree">
<input type="email" name="email" class="contact-form-text" placeholder="Email" required>
</div>
<div>
<textarea class="contact-form-text" name="message" rows="6" maxlength="3000" placeholder="Your message" required></textarea>
</div>
<div>
<button type="submit" id="fcf-button" class="contact-form-btn">Send</button>
<div>
</form>
PHP
<?php
if(isset($_POST['message']) == false) { // If there's no message
echo "Uh oh. Looks like you didn't actually include a message, friend.<br><br>";
die();
}
$destination = "##gmail.com"; // Put your email address here
$subject = "Message from your website!"; // Fill in the subject line you want your messages to have
$fromAddress = "##domain.com"; // Fill in the email address that you want the messages to appear to be from
// Use a real address to reduce the odds of getting spam-filtered.
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$message = str_replace("\n.", "\n..", $_POST['message']); // Prevents a new line starting with a period from being omitted
$message = "First Name: ". $fname ."\n Last Name: ". $lname ."\n Email: ". $email ."\n Message: ".$message."\n";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $fromAddress;
$headers[] = "Subject: " . $subject;
$headers[] = "X-Mailer: PHP/".phpversion();
mail($destination, $subject, $message, implode("\r\n", $headers));
Thanks for your message:
echo $message; ?>
Go back home
?>
As you see I tried to get message from ##domain.com and received it in mygmail#gmail.com. but it didn't work, I received nothing in my inbox. is there anything to do with my gmail and my hosted email.
Your email is not being sent. You can try to capture the error that happened via php's last error function, after sending the email :
print_r(error_get_last());
Firstly, ensure that your email service provider makes allowance for the use of less secure apps, and make sure you have this feature enabled (Be sure to disable it later). My 'from' email was a Gmail account where non-secure apps can be enabled at this address: https://myaccount.google.com/lesssecureapps?pli=1
Secondly, ensure that your local mail server is correctly set up. If you are using XAMPP follow the directions here: https://www.geeksforgeeks.org/how-to-configure-xampp-to-send-mail-from-localhost-using-php/
Next, name the button on your form in order to detect the form submission, I named the button 'submit'.
Then in mail.php use this code
<?PHP
if(isset($_POST['submit']) && empty($_POST['message'])) {
// If there's no message
echo "Uh oh. Looks like you didn't actually include a
message, friend.<br><br>";
die();
}
$destination = "fihriabdelali#gmail.com";
$subject = "Message from your alfidomain.com!";
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$fromAddress=$email;
$message = str_replace("\n.", "\n..", $_POST['message']);
// Prevents a new line starting with a period from being omitted
$message = "First Name: ". $fname ."\n Last Name: ".$lname ."\n Email: ". $email ."\n Message: ".$message."\n";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $fromAddress;
$headers[] = "Subject: " . $subject;
$headers[] = "X-Mailer: PHP/".phpversion();
mail($destination, $subject, $message, implode("\r\n",
$headers));
// mail($to,$subject,$msg,$headers);
echo "Email successfully sent.";
?>
If you are not Abdelali make sure you set $destination to "youremail#domain.com"

Failed to send an email using php [duplicate]

This question already has answers here:
How do I send email on heroku using PHP?
(2 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I'm trying to make my form work so I can receive emails. My website is currently stored on Heroku and everything looks fine, except it doesn't send emails after the form is submitted. Can someone help me please?
index.php :
<form id="contact-form" method="post" action="email.php">
<input class="holder" placeholder="Name" type="text" name="name" required>
<input class="holder" placeholder="Email" type="email" name="email" required>
<textarea class="holder" placeholder="Drop me some lines" type="text" name="message"></textarea>
<div class="button-position">
<button id="button-submit" type="submit"><p id='submit_word'>Submit</p><img class="send-spaceship" src="resources/css/images/send-spaceship.png"></button>
</div>
</form>
email.php:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = "itzikshaoulian#gmail.com";
$email_subject = "Form Submission";
$email_body = "User Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "itzikshaoulian#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: https://itzikshaoulianportfolio.herokuapp.com/");
?>

PHP form not working. Emails not sending [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have a contact form on my website and it does not seem to be sending emails. It was on a server when I have been testing it.
Here is the form.
<form action="" method="post" name="form">
<input type="text" name="name" />
<input type="email" name="email" />
<textarea name="message" ></textarea>
<input name="submit" type="submit" value="Submit">
</form>
And here is the PHP code.
<?php
if(isset($_POST["submit"])){
if($_POST["name"]==""||$_POST["email"]==""||$_POST["message"]==""){
echo "Please fill in the contact form";
}else{
$to = "example#gmail.com";
$subject = "Contact Form";
$name= $_POST['name'];
$email= $_POST['email'];
$message= $_POST['message'];
$headers = "From: example#gmail.com";
mail($to,$subject,$name,$email,$message,$headers);
}
}
?>
I have changed my email address to a dummy one there but it does I have not recieved any emails when I do submit this form though.
Thanks in advance! :)
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$txt,$headers);
//syntax mail(to,subject,message,headers,parameters);
?>
The php mail-function requires a different set of parameters:
Php Mail function
You have to embed $name and $email into your message before passing it to php's mail()

Sending and Receiving mail through php contact form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
Recently, I have purchased a domain and hosting. I've also created a webpage having contact form in it. I want when the user wrote something in textarea of contact form and clicks submit then that message is sended to my gmail account and so that i can reply also to those messages. I've also used this script to do so but its not working.
This is sendemail.php file
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'raunakhajela#gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
This is my contact form code in index.php
<div class="contact" id="contact">
<div class="container-3x">
<div class="block-header"> <!-- Blocks Header -->
<h2 class="title">Contact Us</h2>
</div>
<div class="block-content"> <!-- Blocks Content -->
<form action="sendemailphp" method="post" class="trigger-form-animate">
<input type="text" value="" id="name" name="name" placeholder="Name *" />
<input type="text" value="" id="email" name="email" placeholder="Email *" />
<input type="text" value="" id="website" name="website" placeholder="Website *" />
<textarea type="text" value="" id="message" name="message" rows="3" placeholder="Your Message *" ></textarea>
<div class="clr"></div>
<button>Submit Message</button>
</form>
</div>
</div>
</div>
I've also tried "http://www.mybloggertricks.com/2012/06/connect-your-website-email-address-to.html" this tutorial but its not working. Unable to find "Send through Gmail (easier to set up)" this option in gmail on adding another accounts windoww.
How can i do that?? Plzz hlp
You don't have a named subject form element which may explain why mail is failing and may very well be sent to Spam instead.
For example: <input type="text" name="subject">. Either add one of replace.
You will however need to make sure that this is filled out using a conditional statement
(see further below for an example).
$subject = #trim(stripslashes($_POST['subject']));
with
$subject = "Form submission";
You could also add this instead to your form:
<input type="hidden" name="subject" value="Form submission">
Either this or what I've outlined just above will work.
Many Email clients will either send mail to Spam or reject it altogether if a "subject" is missing, which is clearly missing from your code.
Checking if subject has been filled example:
if(isset($_POST['subject']) && !empty($_POST['subject'])){
// do someting
}
try this,both will work
<?php
$to = "usermailid#gmail.com";
$subject = "Welcome to";
$message = " Hi $username,<br /><br />
Thank you for signing up with us.<br />
Thanks <br />";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <yourmailid#gmail.com>' . "\r\n";
$mail=mail($to,$subject,$message,$headers);
if($mail)
{
$to = "admin#gmail.com";
$subject = "Following Customer Signed Up";
$message = " $username,Customer is signed up with us,<br /><br />
Customer Details:<br />First Name:$firstname<br/>Last Name:$lastname<br/>Email:$email<br/>
Phone:$phone<br/>Zip Code:$zip<br/>Message:$message_cust<br/><br/><br/>
Thanks <br />";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <yourmailid#gmail.com>' . "\r\n";
$mail=mail($to,$subject,$message,$headers);
}
?>

PHP Contact form won't work

I've tried every php contact form tutorial but I can't get any of them to send the email properly. They all just show the code but don't send the email. This is the HTML code I have right now:
<form method="POST" action="scripts/contact.php">
<input id="name" name="name" placeholder="Name*" type="text" /> <br>
<input id="subject" name="subject" placeholder="Subject" type="text" /> <br>
<input id="email_address" name="email" placeholder="Email address*" type="text" /> <br>
<textarea id="message" name="message" placeholder="Your message*"></textarea>
<input id="submit" type="submit" name="submit" value="Send" />
</form>
and this is the php I have:
<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "benmuschol#gmail.com";
$subject = "Hello World";
$message = "Name: $name \n Subject: $subject \n Email: $email \n Message: $message \n";
$headers = "From: $email" . $email;
mail($name,$email,$subject,$message,$headers);
echo "Mail Sent.";
?>
I have decent knowledge of HTMl but next to none of PHP. Any help would be greatly appreciated.
first you be sure that php file is exist in path scripts/contact.php
second look at phpinfo or php.ini for find is smptp server was setting or not
use following php code:
<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "benmuschol#gmail.com";
$subject = "Hello World";
$message = "Name: $name \n Subject: $subject \n Email: $email \n Message: $message \n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: '.$email. "\r\n";
if(mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully.";
}
else
{
echo "Error in Mail Sent.";
}
?>

Categories