Php mail not sending - php

I'm trying to send an email using php but it's not working..
This is my code:
<form method="post" name="contact" action="#contact">
<div class="left">
<label for="author">Name:</label> <input name="nom" type="text" class="input_field" id="author" maxlength="40" />
</div>
<div class="right">
<label for="email">Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" />
</div>
<div class="clear"></div>
<label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0"></textarea>
<input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
</form>
<?php
$name= ($_POST["nom"]);
$mail= ($_POST["email"]);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:<nelson-book#outlook.fr>' . "\r\n";
$suject="Book";
$message = "Nom: <br/>" .$name. "email:<br/> " .$email. "message: " .$_POST["text"];
if (isset($_POST['submit'])) {
mail("nelson-book#outlook.fr", $suject, $message, $headers);
echo" teste";
}
?>
I already used a code SUPER similar to this ant it totally worked.. Can the problem be from the server?
thanks in advance.

check out your SMTP server restriction when you send email, with another hosting domain like, "outlook.fr", somethime this is't allowed.

Related

I have a PHP script to send emails with this code-

I have this PHP code to send emails.
<?php
if (isset($_POST['ajax'])) {
$to = $_POST['to'];
$subject = $_POST['sub'];
$msg = $_POST['msg'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: ".$_POST['name']."<".$_POST['from'].">";
$send = mail($to,$subject,$msg,$headers);
if ($send) {
echo "<p id='success'>✔️ $to</p>";
}else{
echo "<p id='error'>❌ $to</p>";
}
exit();
}
?>
I want to integrate it with the following form.
<form>
<input id="input-1" type="text" placeholder="John Doe" required autofocus />
<label for="input-1">
<span class="label-text">Full Name</span>
<span class="nav-dot"></span>
<div class="signup-button-trigger">Sign Up</div>
</label>
<input id="input-2" type="text" placeholder="john" required />
<label for="input-2">
<span class="label-text">Username</span>
<span class="nav-dot"></span>
</label>
<input id="input-3" type="email" placeholder="email#address.com" required />
<label for="input-3">
<span class="label-text">Email</span>
<span class="nav-dot"></span>
</label>
<input id="input-4" type="text" placeholder="●●●●●●" required />
<label for="input-4">
<span class="label-text">Password</span>
<span class="nav-dot"></span>
</label>
<input id="input-5" type="text" placeholder="●●●●●●" required />
<label for="input-5">
<span class="label-text">Confirm Password</span>
<span class="nav-dot"></span>
</label>
<button type="submit">Create Your Account</button>
<p class="tip">Press Tab</p>
<div class="signup-button">Sign Up</div>
</form>
Is there a way to make it work. I want to use the PHP GET method. Is this possible? How would I get around doing that?
I want to send a PHP GET request, which would then send the email. Do I have to change anything in the form? In the PHP?

My form submission not working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
HTML Codes
<h3>online consultation</h3>
<h5>We have provided contact information down below. You can contact us either by mobile, via email or via contact form. We will at once contact you to discuss your problems! If you have special requirments a consultation can be decided.</h5>
</div>
<div class="col-md-7 col-lg-offset-3 contact-grid-right">
<form method="post" action="mail.php">
<input type="text" placeholder="Your Name" name="name" id="name" required="required">
<input type="text" placeholder="Email" name="Email" id="Email" required="required">
<input type="text" placeholder="Contact No" name="contact" id="contact" required="required">
<input type="text" placeholder="Subject" name="subject" id="subject" required="required">
<textarea rows="2" cols="70" type="text" placeholder="MESSAGE" name="message" id="message" required="required">
</textarea>
<button type="submit" class="slide-btn"> Send your message <i class="fa fa-paper-plane" aria-hidden="true"></i> <br></button>
</form>
</div>
PHP Script
<?php
$n=$_POST['name'];
$mail=$_POST['email'];
$ph=$_POST['contact'];
$ln=$_POST['subject'];
$msg=$_POST['message'];
$to="email#yahoo.com";
$sub="message";
$body="
<html>
<body>
<p><b></b></p><h4></h4>
<table border='0'>
<tr>
<b>Name : </b> $n <br><br>
<b>Email : </b> $mail <br><br>
<b>Contact :</b> $ph <br><br>
<b>Subject :</b> $ln <br><br>
<hr>
<b>Contact Form Message:</b> <br><br>$msg
</tr>
</table>
</body>
</html>";
$headers = "MIME-Version: 1.0". "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8". "\r\n";
$headers .= 'From:'.$mail . "\r\n";
//$headers .= 'Cc: email#yahoo.com.au'; "\r\n";
//$headers .= 'Bcc: '; "\r\n";
mail($to,$sub,$body,$headers);
//echo "<script>alert('Message Send Sucessfully')</script>";
echo "<script>window.location.href='index.html'</script>";
?>
here the solution change the $mail=$_POST['email']; in your php script to $mail=$_POST['Email'];
For keeping your code standard replace the email html input for:
<input type="text" placeholder="Email" name="email" id="email" required="required">

contact form help needed php

I am working on the contact form on a webpage. The HTML and CSS is complete, how it supposed to be. However, now I need to make this button work so it sends an e-mail to the given e-mail address. I am a newbie in PHP, so hope someone could help me out.
HTML code:
<div id="thirdColumn">
<div id="contactOns">
<form action="send.php" method="post" enctype="text/plain" class="form">
<p class="name">
<input type="text" name="name" id="name" placeholder="NAAM" />
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="EMAIL" />
</p>
<p class="text">
<textarea name="text" name="message" id="message" placeholder="BERICHT"></textarea>
</p>
<p class="submit">
<input type="submit" id="sent" value="VERSTUUR" />
</p>
</form>
</div> <!-- End contactOns -->
</div> <!-- End thirdColumn -->
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail_to = 'riksterrr#gmailc.com';
$subject = 'Bericht van een bezoeker '.$name;
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$message;
$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>
2 things that needed to be changed in your HTML form are, get rid of enctype="text/plain"
and change:
<textarea name="text" name="message" id="message" placeholder="BERICHT"></textarea>
to:
<textarea type="text" name="message" id="message" placeholder="BERICHT"></textarea>
You had name="text" which should be type="text"
Since you do not have your own Web server setup with PHP, you will need to find a hosting company that has mail() available in order to run your code properly.

Simple Php Mailer.php and a contact.html, need html help might be missing few tags

Hi im totally new to php, i have a website where i have a contact.html,it has forms where in name, email, insurance type, subject and comments can be filled.
Up on clicking submit button, the specfied email will recieve the details. Cant seem to locate the problem.
here is the html code of contact.html
<form id="ajax-contact-form">
<div class="row">
<div class="span4">
<div class="form-padding">
<label for="f1">Your name(required):</label>
<input type="text" name="name" id="f1" class="form-text" value=""/>
<label for="f2">Insurance type:</label>
<input type="text" name="category" id="f2" class="form-text" value="" size="40"/>
</div>
</div>
<div class="span4">
<div class="form-padding">
<label for="f3">Your email(required):</label>
<input type="text" name="email" id="f3" class="form-text" value="" size="40"/>
<label for="f4">Subject:</label>
<input type="text" name="subject" id="f4" class="form-text" value="" size="40"/>
</div>
</div>
</div>
<div class="row">
<div class="span8">
<div class="form-padding">
<label for="f5">Message(required):</label>
<textarea name="message" id="f5" cols="40" rows="10"></textarea>
</div>
</div>
</div>
<!-- send mail configuration -->
<input type="hidden" value="myemail#gmail.com" name="to" id="to" />
<input type="hidden" value="myemail#gmail.com" name="from" id="from" />
<input type="hidden" value="From contact form" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" class="button red small" value="Submit Form" name="submit" id="submit" /></p>
</form>
AND MY SEND-MAIL.PHP
<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['email'];
//data
$msg = "NAME: " .$_POST['f1'] ."<br>\n";
$msg .= "INSURANCE: " .$_POST['f2'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['f3'] ."<br>\n";
$msg .= "SUBJECT: " .$_POST['f4'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['f5'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
My JS function
// contact form
$("#ajax-contact-form").submit(function() {
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "send-mail.php",
data: str,
success: function(msg) {
if(msg == 1) {
result = '<div class="alert success fade in">Your message has been sent. Thank you!</div>';
$("#ajax-contact-form").hide();
} else {result = msg;}
$('#form-message').hide();
$('#form-message').html(result);
$('#form-message').fadeIn("slow");
}
});
return false;
});
My Questions
There seems to be an error, cant send mails. Im a naive. Any help would be appreciated.
How to do i show a success message after clicking submit button.
Thanks
maybe you have to complete your form open tag
<form id="ajax-contact-form" method="POST" action="send-mail.php">
unless you using Ajax, you have to provide the ajax code in your question.

Mail is not coming properly using php?

I am using below simple code to send mail using php. when i echo the line $headers = "From: . $email\r\n"; //echo $headers; exit; which results like From: . test#email.com.
I found dot is printing before mail address , so mail is coming but not properly.If i remove dot , mail is not even coming.Whats wrong with this code ?
<?php
if (isset($_REQUEST['user_email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['user_email'];
$user_name = $_REQUEST['user_name'];
$user_message = $_REQUEST['user_message'];
include 'contact_mail_form.php';
$to = "testtest#gmail.com";
$message = $contactText;
$subject = "Test Mail";
$headers = "From: . $email\r\n"; //echo $headers; exit;
$headers .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$headers);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
?>
<form id="contact_form" name="ContactForm" action="" method="post" onsubmit="return checkContact(this);">
<div class="wrapper">
<div class="fright">
<div class="name">Message:</div>
<textarea cols="1" rows="1" name="user_message" id="user_message" ></textarea>
<span class="clear"></span> </div>
<div class="fleft">
<div>
<div class="name">Your Name:</div>
<input type="text" class="input" name="user_name" id="user_name" />
<span class="clear"></span> </div>
<div>
<div class="name">E-mail:</div>
<input type="text" class="input" name="user_email" id="user_email" />
<span class="clear"></span> </div>
</div>
</div>
<div class="buttons"><a class="more" href="javaScript:void(0);" onClick="document.getElementById('contact_form').reset()">clear</a> <input class="more1" type="SUBMIT" class="button2" value="Send" name="" /> </div>
</form>
<?php } ?>
Try it like this your dot is acting as string not as concatenation
$headers = "From:" . $email."\r\n";
Maybe because \r\n should be surrounded with " not '
And Also
$headers .= 'Content-type: text/html'. "\r\n";

Categories