User Recommendation Email Body - php

The code below works great. It allows a user to send emails to other people in order to recommend my site.
How can I replace "Michael" below with $_POST['sendername']? I tried and it didn't work.
Thanks in advance,
John
$msg = "<html><body>Hello, your friend Michael recommends that you use <a href='http://www.site.com/'>site.com</a> Please visit the site.<br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}

Simply:
$msg = "<html><body> … ".htmlspecialchars($_POST['sendername'])." … </body></html>";

Related

php mail function is not working even its showing true condition part

my php mail() function is not working even its right here it is
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example#gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail= mail($to,$sub,$msg,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
its alert if part i.e. Your password has been successfully sent to you but i did not received any email please help me and i am not using any HTML css in sending this mail.
your headers are incorrect use your headers in this way it will resolved your problem getting true part is not a big deal
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example#you_domain_name.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if not resolved give me the result you get using var_dump($mail); showing bool(true)
use
$mail= mail($to, $sub, $msg, $headers);
You dont need string as all variables are Already string.
Use this mail($to, $sub, $msg, $headers),
If it returns true, then check your spam folder.
Write your domain name
$headers .= 'From: Your name <example#yorudomainname>' . "\r\n";
example <example#stackoverflow.com/>
no need to use "" in the mail function if you are storing it in a variable allready.
second thing check what you are getting in $email_id; variable is it the correct email address you are trying to send email .
simply use like this
<?php
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail=mail($to,$sub,$msg ,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
?>
Update
also please check your spam folder. as if you are using other domain as from email these emails may go to the spam folder . or you can use these headers
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#yourdimain.com"; // enter your domain email
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Wordpress mail return false

I am using wordpress mail and it returning me false.
pleas help me to checkout what's wrong in code.
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= 'From: abc#gmail.com';
$to ='user#gmail.com';
$mail_resp = wp_mail( $to , 'The subject', 'The message',$headers );
if($mail_resp){
echo "Mail send Sucessfully";
}
else{
echo "Mail Not send";
}
i am getting response mail not send Please help me to out of this what's wrong in this.
Thanks in advance
Try this one
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= 'From: abc#gmail.com' . "\r\n";

Using a sender's name and email address in the header of a PHP email form

I can't get the syntax quite right with PHP. How do I change it to display the sender's full name as well as their email address in the 'From:' part this PHP email script?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['message'];
I tried
$headers .= "From: " . $_REQUEST['email'] '<'$_REQUEST['name']'>'. "\r\n";
But I've screwed up the code somewhere.
Thanks guys!
Mail headers are Person Name <email#example.com> so your header needs to be:
$headers .= "From: $_REQUEST[email] <$_REQUEST[name]>\r\n";

Getting a CC copy of user invite Emails

The code below works great. It allows a user to send a recommendation for my site to a list of friends via email.
For each person that gets the email below, I would like to get an email with that person's email, and the name of the person that sent them the message. If my email address was john#site.com, what code could I use to do this?
Thanks in advance,
John
$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "CC: foo#example.com\r\n";
$headers .= "BCC: foo#example.com\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
Rather than messing about with raw headers, consider using one of the many great APIs available, like Swiftmailer, PHPMailer, or Zend_Mail to name just three. Zend_Mail example:
$mail = new Zend_Mail();
$mail->setBodyHtml('<p>hello</p>');
$mail->setFrom('foo#example.com', 'foo#example.com');
$mail->setSubject('Test Subject');
$mail->addTo('foo#example.com', 'Test');
$mail->addCc('foo#example.com', 'Another Test');
$mail->addBcc('foo#example.com', 'Another Test');
$mail->send();

How to display name in the from address?

I have a site in PHP.In this when I send the invitation to people it takes the from address as mysitename#servername.Instead of this I want o display the Mysitename
.How can I do.I have the code shown below.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:'. $value . "\r\n";
$headers .= 'From:Mysitename'."\r\n";
How can I show like in users email's from address is Mysitename?
Thanks in advance?
$headers .= 'From: Mysitename <mysitename.com>' . "\r\n";
http://php.net/manual/en/function.mail.php
Maybe something along the lines of:
$headers .= 'From: Mysitename <owner#mysitename.com>' . "\r\n";
You need 'From' to be proper email address.

Categories