How to know my mail send to recevier in php - php

I have some problem in sending the mail, my mail not send to the receiver.. but get back email to me. my code is here please suggest me
<?php
if(isset($_POST["c_submit"]))
{
if(($_POST['captcha']!="") || ($_SESSION['captcha_id'])!="")
{
if($_POST['captcha']==$_SESSION['captcha_id']) {
$to_customer = $_POST["mail"];
$subject = "Thanking you for Contacting US";
$mail_body = "
<html>
<head>
<title>Thanking you for Contacting</title>
</head>
<body>
<font face='Verdana'>
Dear ".$_POST["name"].",</br>
<p>Thank you for visiting our website. We have received your enquiry through our web form. We appreciate you considering</p>
<p>Sincerely,</p>
<b>Penis Plug. Ltd.</b><br />
Website:". $site."<br />
Email:" .$email."<br />
<br />
<br />
</font>
</body>
</html>";
$to = "ashish.sws#gmail.com";
$mail_subject = "Contact Form Mail";
$to_mail_body = "
<htm>
<head>
<title>Customer Details</title>
</head>
<body>
<font face='Verdana'>
<table>
<tr>
<th>Name : </th>
<td>".$_POST["name"]."</td>
</tr>
<tr>
<tr>
<th>Message : </th>
<td>".$_POST["message"]."</td>
</tr>
<tr>
<th>Email </th>
<td>".$_POST["email"]."</td>
</tr>
<tr>
<th>Contact No. : </th>
<td>".$_POST["phone"]."</td>
</tr>
<tr>
<th>Company : </th>
<td>".$_POST["company"]."</td>
</tr>
</table>
</font>
</body>
</html>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.'http://www.swatiwebtechnologies.com'.'<'.'ashish.sws#gmail.com'.'> ' . "\r\n";
if(#mail($to_customer,$subject,$mail_body,$headers))
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
#mail($to,$mail_subject,$to_mail_body,$headers);
} else if($_POST['captcha']!=""){
echo '<font color="red"><b>Not Matching, Try Again...</b></font>';
}
}
}
?>
Here i am sending two mail 1 for customer and one for self in customer mail problem arise and self email working fine..plese suggest me

As per the docs, the function returns false on failure to send.
$flgSend = #mail(...);
If this causes your code to show "Mail send completed.", but it still doesn't appear in your inbox, then either it just hasn't arrived yet or a SPAM filter has caught it.

Try this for checking of email sending
if(#mail($to_customer,$subject,$mail_body,$headers))
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}

Suggestions:
What is the exact error, if you remove the error suppression operator?
Are you sure the http://www.com in the from: part is valid?
Many spam blocking list providers will block your mail if you don't authenticate encryped. Then, an answer get back to your inbox that your mail was not delivered.
Search here for "mail php", it will bring you dozens of ideas. Like this:
PHP mail() - mail not sending

Related

Php send mail works but something is going on [duplicate]

This question already has answers here:
Check form input length via PHP with maxlength tag
(1 answer)
Prevent php web contact form spam
(11 answers)
Closed 1 year ago.
I have a php website that is working well. It's allows customer to make online reservation and email is sent to us. We have message field, number of passenger and others. The message field is set to 30 characters limit and number of passenger limit is 2 characters. Works well. However, some hackers are being overwitten the message field to like 1000 characters and number field to 20 characters. These people are like telemaketers. What and how can I prevent this. Do I need to install some security software? Which one?Please suggest. Thanks in advance.
Here's the code
/// Contact page
# of Passenger:
<textarea maxlength="150" placeholder="Message/Notes" rows="5" COLS="60" name="notes" title="Note/Message" style="height:71px; width:133px; margin-top:-47px;margin-left:175px;"></textarea>
<input type="submit" name="submit" value="Send"> <input type="button" value="Cancel" onClick="window.location='index.php';" name="Cancel" >
/// iProcess page
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$notes = $_POST['notes'];
$notes = htmlentities($notes, ENT_QUOTES, 'UTF-8');
$passenger = $_POST['passenger'];
//// email send here
$to = "info#mytest.com"; // Tracking customer for sometime. would remove my email later
$subject = "Reservation";
$message ="
<html>
<head>
<title>Reservation Email</title>
</head>
<body>
<p>Customer Reservation information </p>
<table>
<tr>
<th>Order Number :</th>
<td>$ordernumber</td>
</tr>
<tr>
<th>Number of Passenger :</th>
<td>$passenger</td>
</tr>
<tr>
<th>Messages/Notes :</th>
<td>$notes</td>
</tr>
</table>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
////// more headers
//$headers .= 'From: <info#mytest.com' . "\r\n";
//$headers .= 'Cc: <>' . "\r\n";
$success = mail($to,$subject,$message,$headers);
if (!$success) {
$errorMessage = error_get_last()['message'];
}
else
{ echo "Email send successfully"; }
}
else
{
echo "Unable to connect or send your reservation!";
}
}

How to redirect to home page after submitting the Contact Form?

i have created contact form but i am getting two problems
Reply-To mail is not going.
After Submitting the form page has to redirect to Home page.
For reference please find the attached image and code
Below is the PHP code
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name']; // Get Name value from HTML Form
$email_id = $_POST['email']; // Get Email Value
$mobile_no = $_POST['Mobile']; // Get Mobile No
$msg = $_POST['message']; // Get Message Value
$to = "somasekhar.n#vitalticks.com"; // You can change here your Email
$subject = "'$name' has been sent a mail"; // This is your subject
// HTML Message Starts here
$message ="
<html>
<body>
<table style='width:600px;'>
<tbody>
<tr>
<td style='width:150px'><strong>Name: </strong></td>
<td style='width:400px'>$name</td>
</tr>
<tr>
<td style='width:150px'><strong>Email ID: </strong></td>
<td style='width:400px'>$email_id</td>
</tr>
<tr>
<td style='width:150px'><strong>Mobile No: </strong></td>
<td style='width:400px'>$mobile_no</td>
</tr>
<tr>
<td style='width:150px'><strong>Message: </strong></td>
<td style='width:400px'>$msg</td>
</tr>
</tbody>
</table>
</body>
</html>
";
// HTML Message Ends here
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= "From: New Contact Form <".$_POST["email"].">\r\n"; // Give an email id on which you want get a reply. User will get a mail from this email id
$headers .= 'Cc: somumstr210#gmail.com' . "\r\n"; // If you want add cc
// $headers .= 'Bcc: somasekhar.n#vitalticks.com' . "\r\n"; // If you want add Bcc
$headers .= "Reply-To: ".$_POST["email"]."\r\n";
if(mail($to,$subject,$message,$headers)){
// Message if mail has been sent
echo "<script>
alert('Mail has been sent Successfully.');
</script>";
}
else{
// Message if mail has been not sent
echo "<script>
alert('EMAIL FAILED');
</script>";
}
}
?>
The mail function is deprecated and may not work right! I recommand phpmailer https://github.com/PHPMailer/PHPMailer
How do I make a redirect in PHP?
header("Location: path/to/file");
please check post variables
$variable = $_POST['variable-name'] ?? "default content if $_POST['variable-name'] is undefined";
EDIT: mail() is not deprecated but please use the PHPmailer because it's better

Unable to send mail using php mail() function [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
http://webprojects.co/dev_wed/mail.php trying to send mail from server using this script but i am not been able to send mail from server
<?php
$to = "test#gmail.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webprojects#webprojects.com>' . "\r\n";
$headers .= 'Cc: webprojects#webprojects.com' . "\r\n";
$result = mail($to,$subject,$message,$headers);
if(!$result) {
echo "Error";
} else {
echo "Success";
}
?>
always display error trying to send email using php mail() function
Are you testing the code online or via localhost? The mail() function doesn't work in localhost without SMTP.

Trouble with a Simple PHP Contact Form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I'm having trouble figuring out why my contact form isn't working. I'm relatively new to PHP and from what I can see, everything is linked, but when I go to send the email, nothing is sent to the designated delivery address. Any help would be appreciated!! Thank you!!
My code is below:
HTML
<table width="400" border="0" align="left" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="mail.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
PHP
<?php
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='jordanmcowan#gmail.com';
$submit=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($submit){
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
}
else {
echo "ERROR";
}
?>
Your PHP Code seems wrong to me. This is a corrected version
<?php
// Contact subject
$subject = $_POST['subject'];
// Details
$message = $_POST['detail'];
// Mail of sender
$mail_from = $_POST['customer_mail'];
// From
$header = "from: " . $_POST['name'] . "<" . $_POST['customer_mail'] . ">";
// Enter your email address
$to = 'jordanmcowan#gmail.com';
$submit = mail($to, $subject, $message, $header);
// Check, if message sent to your email
// display message "We've recived your information"
if ($submit) {
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
} else {
echo "An error has been encountered while sending your message. We sincerely apologize and ask you to try again. If that fails as well, please contact us at XYZ-Y234-SADF";
}
The variables haven't been initialized. Please note that these symbols: "" mark the beginning and the end of a string.
These lines are wrong:
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
You're trying to assign the variables to themselves. Try:
$subject = $_POST['subject'];
$message = $_POST['detail'];
etc.
You need to use $_POST variable:
// Contact subject
$subject = isset($_POST["subject"]) ? ($_POST["subject"]) : "";
You haven't set your PHP variables (IE $subject) to your post variables yet. Try changing your PHP variables to use the $_POST variables.
<?php
// Contact subject
$subject = $_POST['subject'];
// Details
$message= $_POST['detail'];
// Mail of sender
$mail_from= $_POST['customer_mail'];
// From
$header="from: {$_POST['name']} <{$_POST['mail_from']}>";
// Enter your email address
$to ='jordanmcowan#gmail.com';
$submit=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($submit){
echo "Thank you for contacting us at Allstar Therapies, Inc.<br /> We will be in touch shortly!";
}
else {
echo "ERROR";
}
?>
You can access to POST parametars by $_POST / GET parametars by $_GET. First check if your redirect works correct.
type:
echo "welcome";
in mail.php
If redirect works the print all Post parametars:
print_r($_POST);
Last you can get one by one
$variable = $_POST['input_name_from_form'];
Hope this is solution for your problem

Form with multiple email fields to multiple recipients

This is my html form. The user will input the email addresses he/she would like to send the html email to.
<form id="form1" name="form1" method="post" action="">
<table width="400">
<tr>
<td>Please enter your email address:</td>
<td<input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Please enter the email addresses you would like to notify below:</td>
<td>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<input type="text" name="email1" id="email1" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email2" id="email2" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email3" id="email3" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email4" id="email4" />
</td>
</tr>
</table>
</form>
This is somewhat the php code.
<?php
$ToEmail = '["email1"]["email2"]["email3"]["email4"]';
$EmailSubject = 'Check this out guys!';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: "noreply#domain.com"\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail(......) or die ("Failure");
?>
<script type="text/javascript">
alert("Success! You have sent the notification to the emails you have entered.");
<!--
window.location = "form.html"
//-->
</script>
How do I:
1. Modify the PHP code so that it will send to the emails inputed by the user?
2. The body message of the notification is a html email. How do I go about adding it to the PHP code?
Your help is highly appreciated. Thanks in advance!
Looks like you need to $_POST the email1, email2 etc. values to a variable then use that as your value for $to in the mail() function - just make sure you add a comma after each:
$to = $_POST['email1'] . ', ';
$to .= $_POST['email2'] . ', ';
$to .= $_POST['email3'];
etc. Leave off the comma for the last email and you should be ready to go.
Regarding the content of your email, you should be able to send html no problem - just store it in a variable for ease of use later, e.g:
$message = '
<html>
<head>
<title>This is the HTML Email</title>
</head>
<body>
<div id="container">
<p>Welcome to the html!</p>
<img src="../img/some_image.jpg" alt="some image"/>
</div>
</body>
</html>
';
then make sure you add the relevant HTML headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Along with any other headers e.g.:
$headers .= 'From: HTML Email <you#example.com>' . "\r\n";
Then call mail() with your defined variables:
mail($to, $subject, $message, $headers);
Hope that helps.
p.s. its all available on the mail function definition: mail()
Look at the php manual for mail
Example:
$toemails = "user#example.com, anotheruser#example.com";

Categories