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.
Related
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
Hai Friends iam trying for an online form submission .whenever i try to submit form it redirects me to MS OUTLOOK but my my form values are not included in that why?
Is it possible or does it require ftp credentials or something.
Give me suggestions..
It redirects you to outlook mostly because you click on mailto: link. You can connect to smtp server to send e-mail via php.
Here you will find how to do it
You don't need FTP which is file transfer protocol you need connection to SMTP which is Simple Mail Transfer Protocol.
Also check PHP manual
If you doesn't want to use PHP and you want send it via your client for example outlook you need do something like this:
<form enctype="text/plain" method="get" action="mailto:webdesign#aboutguide.com">
Your First Name: <input type="text" name="first_name"><br>
Your Last Name: <input type="text" name="last_name"><br>
Comments: <textarea rows="5" cols="30" name="comments"></textarea>
<input type="submit" value="Send">
</form>
Code from this page. However, I don't recommend this solution. Connecting to SMTP via PHP is better.
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
I have a landing page called `index.php' with the following form:
<form action="auto_mail.php" method="post">
<input id="signup" class="span8" type="text" placeholder="Your email" name="signup">
<input type="submit">
<?php
if (isset($_SESSION['got_it']))
{echo "<b>You're all signed up!</b>}
?></form>
In the file auto_mail.php I have:
// code scrubbing user input...
$user_email = $_POST['signup'];
session_start();
$_SESSION['got_it'] = '1';
// code sending me an email when someone signs up.
echo <<<EOD
</b>
<meta http-equiv="refresh" content="0, url=index.php">
</div>
</body>
</html>
EOD;
?>
I've looked at some other SO questions (Using $_SESSION to carry data), but it's not what I'm looking for.
All I want, is for a user to see "You're all signed up" when they enter a valid email; with the email confirm email being sent in the background. This code feels clumsy and awkward. It also flashes the auto_mail.php page briefly.
I tried to set <form action="index.php"..., but it doesn't work because I've set up auto_mail.php such that you can't access it directly.
How can use the code in auto_mail.php, which checks for a valid email address and sends confirm emails, without dealing with both $_POST and $_SESSION, or at least using them better?
If you don't want to have any page reloads whatsoever, you'll have to use AJAX to send the form, instead of utilising the form POST.
If you are using jQuery, or Mootools, they both have built in wrappers to handle ajax calls. Without a helper library, you'll have to look into making an XMLHttpRequest yourself.
Other than that, traditionally, you would redirect the user to a "form submitted" page, or alternatively, have the form action be sent to the same page (in your case, index.php, and have PHP code to handle form data if it is received).
I dont get completely what you want.
I think you try to Verify a Mail Address (after?) that form has been sent. But you cannot access the file via http that does the verification.
Have you thought about including the auto_mail.php?
I think you should consider using one of popular PHP frameworks. I guess you didn't use any in above example. Good framework that also offers MVC structure allows to do operations like this in such a simple way you can't even imagine.
Breaking it down to MVC structure will even make it extremely simple to handle post sending and displaying dependences and results made by it in one action.
Learing good framework at first might look like a waste of time, but believe me - it will pay off very quickly.
For start I recommend you looking at Kohana Framework or, if you're ambitions one - Symfony Framework.
so I've been fighting with this for a few days, and I just can't seem to make it work. Whenever I press the submit button, the browser should send the post variables to write.php, but instead, it just redirects back to the website homepage, or the Document Root. This should be really, really simple, and I've done it before, but now it doesn't work for me. What I want to know is if this is a problem with my webserver setup, or PHP, or just a stupid mistake on my part. It's just a simple HTML form, not really special, so here's the form itself, in index.php:
<p style="font-size:13px">
<?php
$rp = fopen('mainlog.txt', 'r');
while(!feof($rp))
{
$read = fgets($rp);
echo($read).('<br/>');
}
fclose($rp);
?>
</p>
<form action="write.php" method="post">
Name: <input type="text" name="user" /><br/>
Changes:<br/>
<textarea cols="70" rows="8" name="change" style="background-color:#555;color:#ccc;font-family:verdana,arial,helvetica,sans-serif;font-size:13px"></textarea><br/>
<input type="submit" value="Add Entry"/>
</form>
And here's where it send to, in write.php:
<?php
$fp = fopen('mainlog.txt', 'a');
$wr1 = $_POST['change'];
#$my_t = getdate(date("g"));
date_default_timezone_set("America/New_York");
$date = date("n").('/').date("d").('/').date("Y").(', ').date("g").(':').date("i").(':').date("s");
$who = $_POST['user'];
$write = $date.(' by ').$who.('
').$wr1.('
');
fwrite($fp, $write);
fclose($fp);
header('Location: http://www.zennixstudios.com/first/chlog/');
?>
I have tried this both on my Apache 2.2 dedicated server with PHP 5 on FreeBSD8.2, and on XAMPP for Windows, with the same results. I have a suspicion that it may have something to do with PHP, specifically PHP include(), because I have several of those on this page, and when I put this on a friend's computer with XAMPP, but without the included files, the include()s just put errors on the screen, but the HTML form suddenly works fine. So, are there any known conflicts with HTML forms and certain PHP functions?
Other Notes:
The code shown above for index.php is within the main page div, but if you want the whole page source just ask.
I'm pretty sure the error isn't in write.php, because I KNOW that the browser never sends anything to it, because it would at least put the date in mainlog.txt.
If you want to see what this looks like in context, go to http://www.zennixstudios.com/first/chlog/
Thanks,
Chaos
Here is your problem:
<table align="right"><tr><td align="right"><form action="/" method="post">Username: <input action="login.php" type="text" name="uname"/><br/>Password: <input type="password" name="passwd"/><br/><input type="submit" value="Login" align="right"/></td></tr></table>
You never closed the form up in your header for the username and password, so your <form action="/" method="post"> is being used for pretty much the entire page and your write.php form action is being ignored because a form is already, technically, open. You'll need to close the form in your header for the rest of your page to work properly.
To reiterate: nothing is being redirected, you're actually posting all the data from both 'forms' to the location / as specified.