Form won't send to mail - php

I made a from in php and it seems to work. When i hit the submit button it goes to the next page and show the message has been send, except i don't receive anything in my mailbox.
Probably easy to fix but I'm pretty new at this all and tried all afternoon yesterday and running out of ideas.
<form class="well" method="post" action="form.php">
<label><b>Klantgegevens</b></label> <br>
<span class="inline span2">Winkelnaam</span><input type="text" name="winkelnaam" class="span10">
<span class="inline span2">Straat</span><input type="text" name="straat" class="span10">
<span class="inline span2">Huisnummer</span><input type="text" name="huisnummer" class="span10">
<button type="submit" class="btn btn-info">Verstuur</button>
</form>
This is the form.php
<?php
$winkelnaam = $_POST["winkelnaam"];
$straat = $_POST["straat"];
$huisnummer = $_POST["huisnummer"];
mail('xxxx#xxxx.nl');
echo 'Uw bericht is verzonden.';
?>

You did not provide a mail subject and mail message.
See PHP mail() documentation for more info.
mail('xxxx#xxxx.nl', 'My subject', 'Mail message text here');

mail('email#address', 'Subject', 'Plain text message', $optional_headers);
But I recommend using a framework to send email instead of the mail() function.
Take a look at http://swiftmailer.org/

Related

How do i automatically send an email after user submit their email address in the newsletter form?

I want to automatically send an email that says "thank you for signing up for our newsletter form. If you have any questions please email kundeservice#.....no
I have tried multiple different codes that I tried to change but nothing has worked. I need to use the $_GET['epost'] so I send it correctly to the email.
I am not sure if I need to install something on the terminal. Currently using ubuntu 18.04
HTML:
<form name="form" class="forms" action="/backup/formsend.php" id="formn" method="post" >
<div class="email">
<input type="text" name="epost" id="epost" placeholder="E-Post" required>
</div>
<div class="submitknapp">
<input class="knapp" type="submit" name="submit" value="Send"></input>
</div>
</form>
<?php
$email = $_POST['epost'];
$email_subject = "News letter";
$email_content = "thank you for signing up for our newsletter form. If you have any questions please email kundeservice#.....no";
mail($email,$email_subject,$email_content);
?>
mail() function is used to send email to mentioned email address.

Sending emails with Mailgun occasionally hangs and doesn't send email

So ive just implmented mailgun into a website for sending contact form info.
This works some of the time, but mostly the page hangs when i press send with the message "waiting for url..." in the bottom left of chrome.
There is no ssl on the server hence the strange mailgun constructor.
This is my php which is placed just inside the body of my website.
<?php
require 'mailgun-php/vendor/autoload.php';
use Mailgun\Mailgun;
if(isset($_POST['register'])){
$message = "Contact Form.\n\n".
"Name: ".$_POST['name']."\n".
"Email: ".$_POST['email']."\n".
"Message: ".$_POST['message']."\n";
$mg = new Mailgun(*my key*, "api.mailgun.net", "v2", false);
$domain = *my domain*;
$mg->sendMessage($domain, array(
'from'=>'Contact Form <build#<url>>',
'to'=> *email*,
'subject' => ' Contact Form',
'text' => $message
)
);
header('Location: ?sent=1');
}
?>
This is the form code:
<form method="post" action="index.php">
<div class="row 50%">
<div class="6u 12u$(mobile)"><input type="text" class="text" name="name" placeholder="Name" /></div>
<div class="6u$ 12u$(mobile)"><input type="text" class="text" name="email" placeholder="Email" /></div>
<div class="12u$">
<textarea name="message" placeholder="Message"></textarea>
</div>
<div class="12u$">
<button class="button" type="submit" name="register"> Send Message </button>
</div>
</div>
</form>
I'm not getting any errors when the email is not sent. The page will eventually reload after the submit button is pressed but the header redirect is not being applied (which im assuming is because the email was not sent successfully).
The php error logs do not show anything going wrong either.
Thanks
Maybe that's a (very) late answer, but I've just met the same problem. And I discovered, that Mailgun has whitelist of IP addresses, so in case you haven't added there your public IP address, the connection to Mailgun's API will never be established.
At the moment of writing this answer, the whitelist is present under this link: https://app.mailgun.com/app/account/security/api_keys

PHP script keeps sending Email evertime the page is loaded

I have put together a simple contact form for my website. Using PHP to POST the data and send directly to my email address. But for some reason every time I visit the page on my website. I still get the test message Displaying under the Form. Then when I reload the website and visit the link again it still displays the thank you message. and automatically sends an email. Im still in testing mode 2 days before my launch and I need this figure out. Considering I am novice to php I dont know what goes where.... check out my website to get a live view https://trillumonopoly.com (click "Contact Us" link in menu) I would like for the contact form to disappear and echo the thank you message once sent. And reset after the page is reloaded. I am also using Jquery ajax to load all my pages into a div container. So I would like to keep the content inside that div without forwarding to the Echo message page, leaving my index page
Heres My ajax code
$(document).ready(function () {
loadMainContent('main');
$('body').delegate('.navMenu', 'click', function (event) {
event.preventDefault();
loadMainContent($(this).attr('href'));
});
});
function loadMainContent(page) {
$('#main').load('pages/' + page + '.php');
}
here is html for the form:
<div class="general row container-fluid"><br>
<center><img src="img/divider.png" class="img-fluid"></center>
<div class="col-lg-6 col-sm-12">
<img src="img/logo.png" class="img-fluid" height="540px" width="540px">
</div>
<div class="col-lg-6 col-sm-12 container"><center>
<br><h1 class="form-title">Contact Us</h1><br></center>
<div class="container">
<form action="pages/mail.php" method="GET" class="box2">
NAME:
<input type="text" name="name" placeholder="YOUR NAME HERE" required>
<br><br>
EMAIL:
<input type="email" name="email" placeholder="YOUR EMAIL HERE" required>
<br><br>
MESSAGE:<br>
<textarea name="message" rows=10 cols=23 placeholder="YOUR MESSAGE HERE" required></textarea>
<br><Br>
<button type="submit" value="Message Sent" class="btn btn-danger btn-lg" style="background-color:"red">SUBMIT</button
</form>
<center><?php include('mail.php'); ?></center>
</div>
</div>
</div>
Here is My simple PHP:
<?php
$name = $POST['name'];
$email = $POST['email'];
$message = $POST['message'];
mail("info#trillumonopoly.com","ILLUMONOPOLY WEB Contact", $message,"From: $email\r\n");
echo "Thank You For Contacting Us!";
?>
Better than check everything before send mail.
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])){
$name = $POST['name'];
$email = $POST['email'];
$message = $POST['message'];
mail("info#trillumonopoly.com","ILLUMONOPOLY WEB Contact", $message,"From: $email\r\n");
echo "Thank You For Contacting Us!";
}
And send POST request to the index, not mail.php.
<form action="" method="POST">
...
So the user can see your message at the end of contact form.

Can't get form to work

I've searched through the forums and found a lot of threads on this topic but can't seem to find the correct answer or solution for my problem.
I've got a contact form which I can't seem to get working.
HTML:
<form action="php/index.php" id="contact-form" method="post" name="form">
<div>
<label>
<span>Naam: (verplicht)</span>
<input name="vname" placeholder="Uw naam" type="text" tabindex="1" required>
</label>
</div>
<div>
<label>
<span>Email: (verplicht)</span>
<input name="vemail" placeholder="Uw e-mail adres" type="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telefoon:</span>
<input name="vphone" placeholder="Telefoon nummer" type="tel" tabindex="3">
</label>
</div>
<div>
<label>
<span>Bericht: (verplicht)</span>
<textarea name="msg" placeholder="Uw vraag of opmerking" tabindex="4" required></textarea>
</label>
</div>
<div>
<input id="send" name="submit" type="submit" value="VERZENDEN">
</div>
</form>
<!-- /Form -->
And here is the PHP code, I replaced my e-mail adress in the form with MY EMAIL for obvious reasons.
<?php
if(isset($_POST['submit'])) {
$name = $_POST['vname'];
$remark = $_POST['msg'];
$from_add = $_POST['vemail'];
$to_add = "MY EMAIL";
$subject = "Your Subject Name";
$phone = $_POST['vphone'];
$headers = 'From: $from_add';
if ($phone != null){
$message = "Naam:$name \n Opmerking: $remark \n mijn telefoon nummer is $phone";
mail($to_add,$subject,$message,$headers);
}else{
$message = "Naam:$name \n Opmerking: $remark";
mail($to_add,$subject,$message,$headers);
}
}
?>
Ow I am using XAMPP to run a localhost, perhaps that could be the problem but I'm not sure.
using the php mail driver aint good for several reasons ,
u can instead try something call phpmailer http://phpmailer.worxware.com which will teach u a better way of doing things like that without frustration ,also incase later u wanted to use a php framework u will feel right at home because they will mostly be using the same syntax.
note that sending mails at first may take some time ,maybe even hours b4 u get anything ,for that u can use something like a fakesmtp https://nilhcem.github.io/FakeSMTP/ to catch the emails.
I had that same problem with a horrible server which doesn't send emails.
So I used a code that connects to a gmail account and sends the email from there.
try this tutorial:
http://coded-words.tumblr.com/post/6936532107/configure-gmail-as-smtp-in-xampp-to-send-mail
Edit 23.12.2014:
Do you have something like this in your code?
<?php
$message = "The mail message was sent with the following mail";
$headers = "From: youremail#gmail.com";
mail("youremail#gmail.com", "Testing", $message, $headers);
?>
(source: http://jiansenlu.blogspot.co.il/2014/10/php-mail-function-using-gmail-account.html)
If you do have this code:
Try submitting a different email address than the one you used in your code.
Sometimes it goes to the "Sent mail" in your Gmail account without actually showing you that you received a new email. (So you can check your "Sent mail" to see if there is anything over there).

Unable to receive mails using codeigniter email class and yahoo mail as the sender

Im trying to create a "contact us" form where visitors will be able to email the site owner.
so far, my form works if the visitor who filled up the form uses a gmail address. but once they use a yahoo email address the recipient(site owner) does not receive the mail
below is how i did the form
controller
public function send_email(){
$data = $_POST;
$new = $this->base_model->send_email($data);
$this->session->set_flashdata("email_status","Message successfully sent");
redirect(base_url("contact"));
}
model
public function send_email($email_data)
{
$from = $email_data['email'];
$subject = $email_data['subject'];
$message = $this->load->view("emails/message",$email_data,TRUE);
$config['crlf'] = "\n";
$config['mailtype'] = "html";
$config['protocol'] = "sendmail";
$this->load->library('email');
$this->email->initialize($config);
$this->email->from($from,$email_data['name']);
$this->email->to("site owner email address goes here");
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
return $this->email->print_debugger();
}
view
<?php
$attributes = array("id"=>"form_req");
echo form_open("send_email",$attributes);
?>
<div class="controls">
<label>Name</label>
<input type="text" name="name" class="span12 req">
</div>
<div class="controls">
<label>Email</label>
<input type="text" name="email" class="span12 req">
</div>
<div class="controls">
<label>Subject</label>
<input type="text" name="subject" class="span12 req">
</div>
<div class="controls">
<label>Message</label>
<textarea name="message" class="span12 req"></textarea>
</div>
<button class="btn"><i class="fa fa-send"></i> Send</button>
<?php
echo form_close();
?>
have i missed something? or is there a workaround for this?
Is there any reason that the email needs to come "from" the email address that filled in the form? I've had issues in the past with spam filters, Yahoo being one of them, spamming emails where the domain of the website sending the email doesn't match the email address the email is "from". And with good reason, I suppose. Yahoo may be discarding this dangerous looking "spam" before it even reaches the ordinary spam box.
I would try having the emails always come from noreply#your-domain-here.com and add a reply to header if you absolutely want the owner to be able to reply directly to the email.
EDIT:
Found this old question with a similar issue, which suggests that changing the from email should solve it: Everytime my mail goes to spam in phpmailer

Categories