How to edit XAMPP setting to send email from localhost? - php

I am trying to send email from localhost XAMPP, I have updated all the required files but still unable to send Email from localhost.
Regards: M.Tahseen ur Rehman.
php.ini
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail.ini
auth_username=myemail#gmail.com
auth_password=mypassword
After all these update i have created a PHP file mail.php to send mails but its not delivering any Email.
include 'connect.php';
$subject = $_REQUEST['subject'] ; // Subject of your email
$personal_email= "abc#hotmail.com";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['product_type']. "<br>";
$message .= $_REQUEST['message'];
$subject_to_sender= "Confirmation";
$message_to_sender = "Thanks for contacting us";
$name= $_REQUEST['name'];
$email= $_REQUEST['email'];
$message= $_REQUEST['message'];
$product_type= $_REQUEST['product_type'];
$address= $_REQUEST['address'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (#mail($email, $subject_to_sender, $message_to_sender, $headers))
{
mail($personal_email, $subject, $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
On Send Button i also send all the Data into Database, and its successfully inserting data into database.
Kindly guide me.

Related

PHP send mail to multiple recipients without sharing email addresses

I am trying to send email to multiple recipients using PHP. My code is like this
<?php
foreach($subscribers as $subscriber){
$email[] = $subscriber['email'];
}
$emails = implode(',', $email);
$email_from = "email#example.com";
$subject = "My Subject";
$full_name = 'Example Sender';
$from_mail = $full_name.'<'.$email_from.'>';
$email_text = file_get_contents('email.html');
$headers .= 'From: ' . $from_mail . "\r\n".
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";
mail($emails, $subject, $email_text, $headers);
?>
I am able to send emails correctly. But it shows others email addresses in there email box and I don't want to share email addresses with each other. Please help how can I do this. I tried to send email inside the for each loop like this
<?php
foreach($subscribers as $subscriber){
$email = $subscriber['email'];
$email_from = "email#example.com";
$subject = "My Subject";
$full_name = 'Example Sender';
$from_mail = $full_name.'<'.$email_from.'>';
$email_text = file_get_contents('email.html');
$headers .= 'From: ' . $from_mail . "\r\n".
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";
mail($email, $subject, $email_text, $headers);
}
?>
But it sends email to only the first email address inside loop. Please help.
You can add an empty string in the $email field and use bcc headers to add the mail addresses. bcc makes sure the receiver can't see the other email addresses.
$headers .= "Bcc:email#example.com" . PHP_EOL;

PHP Mail() Function injecting "#cp-in-3.webhostbox.net" with "from" address in feedback form

I have been facing many issues while sending a mail through feedback form. First, the function was sending the mail while it was in the localhost. But after uploading it to the remote server, it stopped sending. Anyway, I fixed somehow. Now it is sending the mail, but injecting some more string to the "FROM" address. Please have a look at the code I have written and this what I am getting after receiving the email.
Code====>
<?php
function putinplace($string=NULL, $put=NULL, $position=false)
{
$d1=$d2=$i=false;
$d=array(strlen($string), strlen($put));
if($position > $d[0]) $position=$d[0];
for($i=$d[0]; $i >= $position; $i--) $string[$i+$d[1]]=$string[$i];
for($i=0; $i<$d[1]; $i++) $string[$position+$i]=$put[$i];
return $string;
}
$from1 = $_POST["email"];
$from = preg_replace('/[^a-zA-Z0-9#\.]/', ' ', $from1);
$at_pos = strpos($from, "#");
$from = putinplace($from, "\\", $at_pos);
$subject1 = $_POST["subject"];
$subject = preg_replace('/[^a-zA-Z0-9\']/', ' ', $subject1);
$message1 = $_POST["body"];
$message = preg_replace('/[^a-zA-Z0-9\']/', ' ', $message1);
$to = "emailidtosend#gmail.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'From: abc.co.in' . "\r\n". 'Reply-To: emailidtosend#gmail.com' . "\r\n" .'X-Mailer: PHP/' . phpversion();
$headers .= 'Content-type : text/html; CHARSET=ISO-8859-1' . "\r\n";
$headers = "From:" . $from . "\r\n";
if(mail($to,$subject,$message,$headers)){
echo "<script>alert('Email Sent Successfully. We will Get back to you Very soon.');</script>";
echo "<script>window.open('contact-us.php', '_self');</script>";
}else{
echo "<script>alert('Unable To Send The Email.');</script>";
echo "<script>window.open('contact-us.php', '_self');</script>";
}
?>
And Output===>
username\#gmail.com#cp-in-3.webhostbox.net (Look at the last portion of "FROM" address)
You do not need to put via cp-in-9.webhostbox.net
You need to configure you php.ini file in your web server.
Step 1. Find php.ini file
If it's not there then create one in home directory and add codes below
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = me#example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path = /usr/sbin/sendmail
this path "/usr/sbin/sendmail" is specific to server.
To get yours just create a php file with code
<?php
phpinfo();
?>
and hit that file from web browser you will get the path value for key sendmail_path
One small and simple example for sending email in php is as :
<?php
// Set up parameters
$to = "Vivek.kumar#xyz.com";
$subject = "Your password";
$message = "<p>Hello Homer,</p>
<p>Thanks for registering.</p>
<p>Your password is: <b>springfield</b></p>
";
$from = "vivek#domainname.com";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\n";
$headers .= "From: $from" . "\n";
// Send email
mail($to,$subject,$message,$headers);
// Inform the user
echo "Thanks for registering! We have just sent you an email with your password.";
?>

Php mail. Can't get email on one address

I have a problem with my mail in php. I code form to send email. I receive email on gmail but I have other mail address and I can't get email on it.
I checked in spam and there is no email also.
Below is my code.
<?php
$emailErr = "";
$endMessage = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Proszę uzupełnić pole e-mail";
}
else if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$namesurname = $_REQUEST['name_surname'] ;
$email = $_REQUEST['email'] ;
$number = $_REQUEST['number'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$message = $subject . ": " . $message . " " . $number . " " . $namesurname . " " . $email;
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
mail("szafor#szafor.pl", "Zamówienie pomiaru",
$message, "From: formularz#szafortest.pl \r\n"."Content-Type: text/plain; charset=UTF-8\r\n");
$endMessage = "Dziękuję za przesłanie wiadomości.";
}
}
?>
One important thing to consider with sending mail is that you should at least have the return path of the message be an email address that is actually hosted on the server that you are sending from.
You can set the From and the Reply-To address as any address, but the return-path should be set to a valid email address hosted on your server. Let's say that you want the "reply" button to send back to "this_email#wherever.com" but the server you are using hosts email for "mydomain.com". Create an email account on your server, "info#mydomain.com" for example.
$recipient = "sendto#email.com";
$subject = "Test email";
$message = "This is the message.";
$headers .= "From: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Reply-To: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Return-Path: Your Name Here <info#mydomain.com>\n\r";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .="X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .="MIME-Version: 1.0\r\n";
mail($recipient, $subject, $message, $headers);
I have found that the more valid header information that I provide, the more likely the email will be delivered. Right now these headers always work for me, and I have a scheduling program that is sending email to a hundred different email addresses every day. See if that works better for you.

Can we include 2 Mail() functions in 1 Page?

I want to sent 2 different E-Mails to 2 different persons on 'Send Message' Button. I have few questions regarding this.
Is it possible to send Multiple Emails from same Page.
I have written the following code but its not sending Any Email and returning Error Message in return.
<?php
include 'connect.php';
$subject = $_REQUEST['subject'] ; // Subject of your email
$personal_email= "abc#hotmail.com";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['product_type']. "<br>";
$message .= $_REQUEST['message'];
$subject_to_sender= "Confirmation";
$message_to_sender = "Thanks for contacting us, Our representative will contact you shortly.";
$name= mysql_real_escape_string($_REQUEST['name']);
$email= mysql_real_escape_string($_REQUEST['email']);
$message= mysql_real_escape_string($_REQUEST['message']);
$product_type= mysql_real_escape_string($_REQUEST['product_type']);
$address= mysql_real_escape_string($_REQUEST['address']);
if($address== "")
{
$address= "No Address is given.";
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (#mail($email, $subject_to_sender, $message_to_sender, $headers))
{
mail($personal_email, $subject, $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
To answer your former question, I can say Yes, its possible to use mail() function multiple times.
For the later question, the opening bracket on last if() statement is not closed. Add } after echo 'sent'; statement.

No e-mail is send using mail function in PHP

I just need that when form is submitted mail is send to recipient. My form submitted with Response code of 200k but mail is not Delivered. I have installed sendmail.
sendmail.php code:
if(isset($_POST['submit']))
{
$subject = $_POST['subject'];
$to = "abc#gmail.com";
$from = $_POST['email'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
mail ($to, $subject,$msg, $headers);
echo "sent";
}
installed mail server in php.ini file:
[mail function]
; Setup for Linux systems
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = me#myserver.com
mail ($to, $subject,$msg, $headers);
echo "sent";
instead of this ,first check if the mail is sent
$mail=mail ($to, $subject,$msg, $headers);
if($mail){
echo "sent";
}else{
echo "failed.";
}
By this actually u can know whether your mail function in working or not
if it is not working.the problem can be with SMTP settings in your localhost
enable errors in php if not enabled using
ini_set('display_errors',1);
Have you checked mail settings in you php.ini ?
PHP Runtime Configuration
If you don't have access to the PHP settings you can use PHP Mailer to deliver emails with your own parameters

Categories