Collecting data from php using mail() function [duplicate] - php

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

Related

Browser loads up my PHP file rather than sending an email [duplicate]

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

Trying to create a contact form using PHP with Bluehost [duplicate]

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";
}
?>

How can I set up a contact form on my website? [duplicate]

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.

PHP mail from an HTML form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I'm trying to setup a contact form on a website I'm working on, the code for which looks like this:
<form action="contact.php" method="POST">
<ul>
<li>
<label for="name">Name:</label><br>
<input type="text" name="name" />
</li>
<br>
<li>
<label for="email">E-mail:</label><br>
<input type="email" name="email" />
</li>
<br>
<li>
<div id="label">Enquiry:</div>
<select name="interest"><br>
<option value="Wedding">Wedding</option>
<option value="Engagement/Couple">Engagement or Couple</option>
<option value="Portrait">Portrait</option>
<option value="Family">Family</option>
<option value="Children">Children</option>
</select>
</li>
<br>
<li>
<label for="message">Message:</label><br>
<textarea name="message" cols="40" rows="6"></textarea>
</li>
<br>
<li>
<button class="submit" type="submit" value="Submit">Submit Form</button>
</li>
</ul>
</form>
Originally I just had the form action as a mailto:myemail#example.com but I would obviously prefer for the user to just submit the form and the email be sent instead of just opening their email application. I'm trying to build a PHP script to do this but am having no luck as yet, probably because this is my first time ever even looking at PHP, let alone trying to write it.
I have looked at many different examples and delved into the PHP manual for help but whatever I write leads to the same result, pressing the submit button on my form and receiving nothing in my inbox. So I started a sort of fault finding process to try and help determine the problem. I would start with really basic PHP scripts and then try and add more to each one and see where it broke.
I started by changing the form action to the php test script as below:
<?php
phpinfo() ;
?>
This worked fine and displayed the php info page as it should. Great so I know that my host supports php and has it installed. This is not the problem then. Second I changed the form action to this code below:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
And again it worked as expected showing the Hello World paragraph. After this I attempted the most basic php mail script I could think of which looked like this:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
mail('myemail#example.com', 'Contact Form', 'This is a test');
?>
</body>
</html>
All this succeeds in doing when I press the submit button on my form is displaying a blank page with the url of my php script in the address bar of my browser and from this I have received no email. Not in my inbox or junk folder, nowhere. As this is such a simple script I have two trains of thought at the min. 1 is that I'm just doing something very basic wrong, which is a high possibility considering my extremely limited knowledge of php. 2 is that something more complicated is going on, maybe php settings of my host are not correct for what I'm attempting to do? I don't know.
I apologise for this question being so long winded, I just wanted to show what I'd done so far in the hope that it will help you guys with any assistance you can give me. Any help with my problem is greatly appreciated, thank you.
One thing to consider is that your email may be getting blocked by your email provider. I have a host with Heart Internet and I've tried sending an email from the website being hosted by Heart to my AoL account and the email does not show up at all. But any emails going to Gmail do. This is because AoL has blocked all emails coming from Heart because of websites producing spam.
I will input some PHP code below which should work:
// Input your desired location instead of email address
$to = 'email address';
$subject = 'Test email';
$message = '<html><body>';
$message .= '<h1>This is an email.</h1>';
$message .= '<p>I hope you like it.</p>';
$message .= '</body></html>';
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';
mail($to,$subject,$message,$headers);
Or you are running from localhost.
Or your SMTP settings in your php.ini file aren't configured correctly
My host has blocked mail server for the package I'm on. Something I should've checked but in my frustration I've overlooked it. Thanks for not answering my stupid question with stupid answers guys. Sorry to have made you read all that for nothing really but a fresh head and pair of eyes always works wonders!!
check at the top of the form, there is written <form action="contact.php" method="POST"> that's mean form values are posted to contact.php file where the mail functions is written to send email with form's data. Please show the code of contact.php

PHP Form Mailer on an SSL Site

I'm having a hard time finding a solution to a problem that should have a very simple solution.
I created a PHP form mailer that worked on my customer's site. He then decided to get an SSL certificate, and since then, the form mailer doesn't work. I don't get any errors at all. Everything appears to have been sent, but I haven't received any emails from the form.
I then created a nonsense form with one field and a very basic PHP form mailer to see if I can troubleshoot the problem, but even this basic code does not work.
Does the mail() function not work with SSL? I'm thinking I'm missing something relevant somewhere. This is the first time I've worked with SSL, but I'm more than capable of creating the code if only I can get some direction, which is the reason for this post. Any guidance, direction, or critique will be very appreciated.
---MY NONSENSE FORM USED FOR TESTING---
<form id="form1" name="form1" method="post" action="testFormsub.php">
<input type="text" name="text1" id="text1" />
<input type="submit" name="button" id="button" value="Submit" />
</form>
---MY BASIC PHP FORM MAILER---
<?php
$test = $_POST['text1'];
$to="email#email.com";
$subject="Thank you for registering.";
$header="From: TEST EMAIL <email#email.com>";
$message="PLEASE WORK...$test \r\n";
$sentmail = mail($to,$subject,$message,$header);
?>
Are you using two separate pages for mailing as in a form page and results page?
If so, are you using SSL for both pages?
if not, the problem likely lies in the fact that your sendmail page uses SSL and your testFormsub.php is not using SSL.

Categories