This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I want the form to send the contents to my email, instead it's just displaying my php code in a new window, can anyone help? here is the code:
Index
<form action="send.php" method="POST">
Name: <br><input type="text" name="name"><br><p>
Request: <br><textarea name="request"></textarea><p>
<input type="submit" name="submit" value="Send!">
</form>
PHP:
<?php
$name = $_POST['name'];
$request = $_POST['request'];
$to = "myemail#email.co.uk";
$subject = "It's just a test";
$body = "This is just a test to see if things are working okay \n\n $request";
mail ($to,$subject,$body);
echo "Message sent!"
?>
Few tips for beginners
First Configure your Xampp form send email How to configure XAMPP to send mail from localhost?
Check if the data is coming to send.php by print_r($_POST)
Follow this tutorial for sending email from here
Related
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 4 years ago.
I have set up a contact form which is to send email to anyone from WordPress page. It's sending email but all are going to SPAM folder. How to prevent it to go to Spam folder but go to Inbox?
however, I gave it try from another wordpress site, all emails going to inbox perfectly, and I've found a difference that is all email going to inbox has one extra line in details that is-
mailed-by: p6plcpnl0235.prod.phx3.secureserver.net
But the emails going to the SPAM folder doesn't have this above line, Is it can be a cause? If so how to enable this secureserver.net
Can anyone please help me?
Here is what I am using in page-
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "admin#mail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($email, $subject, $comment, "From:" .$admin_email);
//Email response
header('Location: /email-sent');
}
//if "email" variable is not filled out, display the form
else {
?>
<div class="container send-email-form-wrapper">
<div class="row">
<div class="send-email-form">
<form method="post">
<li> Email: <input name="email" type="text" /> </li>
<li> Subject: <input name="subject" type="text" /></li>
<li> Message: <textarea name="comment" rows="5"></textarea></li>
<li><input type="submit" value="Submit" /></li>
</form>
</div>
</div>
</div>
<?php
}
?>
This is more about your hosters internal sendmail mail setup that is used by the mail() function. If possible, try to use an tested SMTP mailer like Swiftmailer or PHPMailer instead. That way you could work around the sendmail smarthost configuration issue.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm new to PHP, but I found some sample code for a web form. I adapted it like this, in a file called contact.php:
<?php
mail('contact#mywebsite.com', $_POST['name'], $_POST['email'], $_POST['subject'], $_POST['message']);
?>
<p>Your message has been sent.</p>
and here's the HTML:
<form action="contact.php" method="post" enctype="text/plain">
Name<br>
<input type="text" name="name" value=""><br><br>
Email<br>
<input type="text" name="email" value=""><br><br>
Subject<br>
<input type="text" name="subject" value=""><br><br>
Message<br>
<textarea name="message" rows="10" cols="50"></textarea><br><br>
<input type="submit" value="SUBMIT">
</form>
It wasn't working, so I did some research and discovered Bluehost requires you to use their own Bluemail for this. So I ditched the PHP and followed their tutorial. That didn't work either, so I did some more research and discovered they discontinued Bluemail. So I went back to the PHP method and changed the email to a bluehost email address (apparently that's required as well).
Long story short, I checked my junk mail folder and found some of the test emails I had tried to send from the form, but they are all blank. No subject, no message content.
So it seems like the contact form is working (in that it sends an email), but the actual information inputted in the form is not coming through. I assume there's a problem with my PHP code?
Any help would be greatly appreciated!
Seems you are using wrong syntax for mail
Try
<?php
$msg = $_POST['name']."<br/>". $_POST['email']."<br/>". $_POST['message'];
mail("contact#mywebsite.com",$_POST['subject'],$msg);
?>
You can try this code (perhaps will work for you):
<?php
$msg = $_POST['name']."<br/>". $_POST['email']."<br/>". $_POST['message'];
if (isset($_POST["email"])) {
mail($_POST["email"],$_POST['subject'],$msg);
echo "Your message has been sent.";
}else{
echo "N0, mail is not set";
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I've done my research on this but can't seem to get it to work.
I'm looking to add a contact form to my website that sends an email directly to me. I've watched videos and used code I've found online but nothing works. I even temporarily disabled my website and uploaded just a blank contact form (code below) and a php file (code below) with my only results being that the echo command at the end of the PHP file DOES show up. The email, though, still does not send.
What am I missing? Thank you!
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Temp</title>
</head>
<body>
<form method="post" action="send.php" name="contact_form">
<p>
<input name="name" type="text" />
</p>
<p>
<input name="email" type="text" />
</p>
<p>
<textarea name="message"></textarea>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</form>
</body>
</html>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "email#myemail.co";
$subject = "Contact Form Submission";
mail ($to, $subject, $message, "From: " . $name);
echo "Your message has been sent. You can expect to hear from us soon.";
?>
I'm sure this is a duplicate, but I just wanted to mention a couple of things to check.
Does your mail() call return true? I would check that. It's possible that your PHP installation is not set up correctly to send mail. There are countless posts on how to check and configure that, which I would suggest reviewing if you haven't already (here's one, for example).
Depending on where you're hosting this, your host's configurations may restrict any outgoing mail that is not from the domain you're hosting. (I've had this problem myself on shared hosts.) Here you're setting the "from" header as the name of the person submitting the form (which would look something like: "From: John Doe"). This may be a problem either on the sending or receiving end of the email (either side rejecting it because it doesn't come from an email address, or a valid email address, etc). Try setting the "from" value to an email address valid on your host (e.g., "myname#mydomain.com"). Then, just include the person's name and email address in the $message of the email.
Hope that helps.
This question already has answers here:
Html form in email
(3 answers)
Closed 7 years ago.
I create many newsletters. Is it possible to add a php form in email ? I explain, the customer open this email and on this email he see an input to add his email. Is it possible for me to keep the data ? For example we can imagine a simple input to subscribe newsletter.
ya its possible... you need have a form in your email template and in form action you need to specify the php file which is there in your domain
E.x:
in your email template
<form method="GET" action="http://www.yourdomain.com/back_end_file.php">
<label>Email id</label>
<input type="text" name="email" />
<input type="submit" value="submit" />
</form>
In your server file i.e : http://www.yourdomain.com/back_end_file.php
<?php
echo $email = $_GET['email'];
?>
If it gives some cross domain issue then paste below code in first line in http://www.yourdomain.com/back_end_file.php this file
<?php header('Access-Control-Allow-Origin: *'); ?>
I hope this works...
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am having trouble using the mail() function in php. I am currently learning about it at treehouse but no matter what i do, i just couldnt seem to send the email.
Previously, there were a lot of codes used to avoid spammers and bots. I tried to dumb it down to the simplest and it still wouldn't work, meaning that i still can't use it to send an email despite uploading the file to a free web host that supports php just for testing purposes using filezilla.
May I know what did i do wrong?
The webhost name is www.000webhost.com
Below is the code:
<?php
$to="theteam#theopencircles.com";
$subject="this is from your mother";
$message=$_POST["message"];
if($_POST){
mail($to,$subject,$message);
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
<input type = "text" name="message" id="message"/>
<input type = "submit" name = "submit" id="submit" value="submit"/>
</form>
</body>
</html>
<?php
if($_POST["submit"] == 'submit')
{
$to="theteam#theopencircles.com";
$subject="this is from your mother";
$headers="sender email-id";
$message=$_POST["message"];
mail($to,$subject,$message,$headers);
}
?>
you can switch to php mailer https://github.com/PHPMailer/PHPMailer phpmailer has all email related readymate functions
same time it problem from server side configuration. Please config your php.ini or contract to server admin