Changing CGI-Mailer in PHP mail script [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a php script that sends an email from an HTML form. The issue is that the sender shows as CGI-Mailer in my inbox.
How can I set the sender address to be that of the sender and not CGI-Mailer?
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = 'info#complexny.com';
$fromsubject = $_POST['fname'];
$subject = $_POST['fname'];
$fname = $_POST['fname'];
$url = $_POST['url'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$headers = "From: $mail \n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$message = $_POST['message'];
$to = $youremail;
$subject = ''.$fromsubject. ' is interested in a project with you.';
$body = '
Client: '.$fname.'
Phone Number: '.$phone.'
URL: '.$url.'
E-mail: '.$mail.'
Message:
'.$message.'
';
echo "<p style='text-align:center'>Thank you for your feedback. We will be in contact shortly.<br/>Continue to <a href='/'>The Company/a></p>";
mail($to, $subject, $body);
} else {
echo "You must write a message. </br> Please go to <a href='/contact.php'>Contact Page</a>";
}
?>

You are not passing the additional_headers parameter to the mail function. Change the line with the call to mail to:
mail($to, $subject, $body, $headers);

I would suggest using PHPMailer rather than mail(). You can see how to do what you're after in the answer to this question: Setting replyTo field in email
Quoting from that question:
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is email2#example.com
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1#example.com
You can find more info on PHPMailer here: https://github.com/PHPMailer/PHPMailer

Related

Php mail function worked and then stopped [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed last year.
So i have my code and styling finished, first it worked tried a few times and it was sending mails.
the next day it was not sending any more, testing this on live server no localhost.
i need this code to work so clients can ask for information and we give them offers.
i have read it is better to use request method but have never used it, but if this may be a solution i will try it.
This is a test version of the website
https://www.two4u.be/test/index.php?page=contact
searching for a few days what the problem could be.
<?php
// email info to send
$to = "sammy#two4u.be"; // this is your Email address
$subject = "Offerte aanvraag website";
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$straat = $_POST['straat'];
$gemeente = $_POST['gemeente'];
$nummer = $_POST['nummer'];
$tijdstip = $_POST['tijdstip'];
$systeemkeuze = $_POST['systeemkeuze'];
$budget = $_POST['budget'];
$termijn = $_POST['termijn'];
$extra = $_POST['extra'];
// create email headers
$headers = "From: Two 4 U <noreply#two4u.be>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
// create the html message
$message = "<html>
<body>
<h1> Offerte aanvraag via website</h1>
<h2> Gegevens van de klant</h2>
<p> <b>email:</b> $from <br>
<b>naam:</b> $name <br>
<b>Adres:</b> $gemeente <br>
$straat<br>
<b>Telefoon:</b> $nummer<br>
<b>Wanneer klant bereikbaar is:</b> $tijdstip<br>
<b>Welk systeem van ons:</b> $systeemkeuze<br>
<b>Klant budget hiervoor:</b> $budget<br>
<b>Binnen welke termijn:</b> $termijn<br>
</p>
<p> <b>Extra informatie:</b> $extra </p>
</body></html>";
// send email to user
if (!empty($_POST['mail'])){
mail($to, $subject, $message, $headers);
}
?>
In your submission form, there is no input box with the name="mail",
Hence change
if (!empty($_POST['mail'])){
mail($to, $subject, $message, $headers);
}
to
if (!empty($_POST['email'])){
mail($to, $subject, $message, $headers);
}

PHP E-mail form - Define sender

I'm trying to create a HTML form, which will in the end send an e-mail using the folling PHP Code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$destinationemail = "myemail#domain.com";
$emailcontent = "Name: {$name}\n\nE-Mail: {$email}\n\nMessage: {$subject}\n{$message}";
$subject = "Contact from Domain.com";
$from = $email;
mail($destinationemail, $subject, $emailcontent) or die("Error!");
echo "Thank you $name!";
?>
The problem is, everytime i receive an e-mail, i get is as if being sent from a what i guess is the Webhost general e-mail.
htgkaylg#server776.web-hosting.net
<htgkaylg#server776.web-hosting.net>
dom 08/10/2017, 18:40
Você;
I would like it to be received something like this:
myemail#domain.com
<myemail#domain.com>
dom 08/10/2017, 18:40
Você;
Is it possible?
Thank you,
Vítor
You have to use the Header as 4th parameter in mail() function.
Add this line and change mail as follow:
$headers = "From:" . $from . "\r\n";
mail($destinationemail, $subject, $emailcontent, $headers) or die("Error!");
Ref. https://www.w3schools.com/php/func_mail_mail.asp

PHP sending mail but with missing information [duplicate]

This question already has answers here:
Email Form more than 20 values
(3 answers)
Closed 6 years ago.
I am pretty new to all this and I need some help. This is the most basic mail function in PHP.
<?php
$headers = "Content-Type: text/html; charset=UTF-8";
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$to ="maria#mkitra.com";
$subject2 = "Work";
mail($to, $subject2, $message, $headers, $name);
echo "Message Sent";
?>
It does send the email but my problem is that the mail function doesn't include either the user's email nor their phone number. How do I include them in the email?
I have tried
mail($to, $subject2, $message, $headers,$phone,$email $name);
But it says, the mail function can take maximum 5 parameters. I am confused.
You can use this
<?php
$to = $_POST['email']; //Whom you want to send
$from = "maria#mkitra.com"; //Your email id
$subject = $_POST['subject'];
$message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body><span>Mobile</span><span>'.$phone.'</span><span>Name‌​</span><span>'.$name.'</span></body></html>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "Message Sent";
Email only send to and email subject and email body and email type mean header. No send mobile number or name or any other things. If you add this then you add on your under email body

PHP Contact Form not Sending?

Ive got a contact form that isnt sending but is outputting that the message is sent? Can anybody see a problem?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "myemail#email.co.uk";
//begin of HTML message
$message = "
From : $name,
Email: $email,
Subject: $subject,
Message: $message ";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Website Enquiry";
if (isset($_POST['name'])) {
// now lets send the email.
mail($to, $subject, $message, $headers);
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.');
} else {
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.');
}
?>
The "From" header should have a syntactically correct email address. You also need to check the return value of the "mail" function.
$header .= "From: Website Enquiry <enquiry#website.com>";
PS: Please improve your code formatting.
Try to enter an email at From: in $headers.
Like $headers .= "From: youremail#provider.com" or
$headers .= "From: Website Enquiry <youremail#provider.com>"
And you should change it to
if(mail(...)) {
//success
}
else {
//email failed
}

php mail function

<?php
$sendto = "account#gmail.com";
$subject = "email confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
# send the email
mail($sendto, $subject, $message);
?>
this is the code that i wrote to test mail function on localhost.
i have ran the script in browser for several times and still dun receive any email in my mail box.
Do I need any additional configurations?
thx in advance!
Basically is hard to send a mail from localhost to any mail providers.
They have big restrictions on the incoming mails, and the simply mail() won't work.
You need to use an SMTP server.
and define that server in php configuration
smtp = localhost #(here should be your smtp server)
smtp_port = 25
if you don't have an SMTP server, try to pass all headers like in PHP examples:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
http://www.php.net/manual/en/function.mail.php
You need to make sure that you have your PHP installation set up to use a working SMTP Server. You might find what you're looking for in answers to this question. Failing that you'll likely need to test your script on your live web server.
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'yourname#yourwebsite.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message"
?>
<?php
$to = "inspiretechpark#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1#website-name.com, name2#website-name.com,name3#website-
name.com";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1#website-name.com, name2#website-name.com,name3#website-
name.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$headers .= "Cc: someone#domain.com \r\n";
$headers .= "Bcc: someoneelse#domain.com \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
Try This Guys..This Is For Sending Mail
Try this:
<?php
$sender = 'email#example.com';
$recipient = 'email#example.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
If you are working with localhost then, i hope it will never work. It will work only on a mail configured server. Please try on it.

Categories