Hyperlink not getting displayed in Php mail - php

I'm trying to email a link thru PHPMail. Somehow link is showing as plain text in email.
I want that link should be clickable when received in email. Currently it is showing as plain code.
Below is the code, please help!
<?php
$name=$_POST['firstname'];
$email=$_POST['email'];
$phoneno=$_POST['phoneno'];
$com=$_POST['comment'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
?>
Print Boss your receipt
<?php
//$link="hello.php?a=$name&b=$email&c=$phoneno&d=$com";
$to = "ketanjoshi1993#gmail.com";
//$from = $email;
$subject = "send email in pdf format";
$message = "<a href='#'>test</a>";
$email = mail($to,$subject,$message);
if( $email == true )
{
echo "sent";
}
else
{
echo "not sent";
}
?>

You forgot to use your headers in your mail call:
$email = mail($to, $subject, $message, $headers);

So you forget to add the headers
try adding it as
$email = mail($to,$subject,$message, $headers);
It will work

You forget to add the headers
You can do like this :
$email = mail($to,$subject,$message, $headers);
If you don't pass the header parameter in PHP mail() function , default headers will be set & your will be treated as simple text body.

Related

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.

php mail not sending to outlook.com

my contact form is not sending emails to outlook.com
i have tested it on other email accounts and works just fine.
is there anything i can do to solve that issue?
my php code is the following
<?php
$to = 'xxx#xxx.gr';
$headers = 'Content-type: text/plain; charset=UTF-8' . "\r\n";
if(isset($_POST['fullname'])){
$subject1 = mysql_real_escape_string($_POST['fullname']);
$mail = mysql_real_escape_string($_POST['email']);
$message = mysql_real_escape_string($_POST['message']);
$subject = " $subject1 $mail";
mail($to, $subject, $message, $headers);
header("location: contact.php");
exit();
}
?>
thank you in advance

Why the mail content sent are the raw html codes?

Mail content:
<html><head></head><body><p> Message : 鏽嫌╒杜米土 杯屎</p>Share Link : Press here to enter <br><img src ='http://203.80.1.28/FlippingBook/development/demo/medium/Web081112_P070_medium.jpg' /></body></html>
PHP:
if (isset($_POST["data"])){
$info = explode("&", $_POST["data"]);
$headers = 'MIME-Version: 1.0\r\n';
$headers .= "Content-Type: text/html; charset = \"UTF-8\";\n";
$headers = "From: =?UTF-8?B?" . base64_encode(substr($info[0],strpos($info[0],'=')+1, strlen($info[0]))) . "?=";
$to = substr($info[1],strpos($info[1],'=')+1, strlen($info[1]));
$subject = "=?UTF-8?B?" . base64_encode('日報分享') . "?=";
$message = trim(substr($info[2],strpos($info[2],'=')+1, strlen($info[2])));
$message = '<html><head></head><body><p> Message : '.$message;
$url = substr($info[3],strpos($info[3],'=')+1, strlen($info[3]));
$message = $message. '</p>Share Link : Press here to enter ';
if (isset($info[4])){
$firstImg = substr($info[4],strpos($info[4],'=')+1, strlen($info[4]));
$message = $message."<br><img src ='".$firstImg."' />";
}
if (isset($info[5])){
$secondImg = substr($info[5],strpos($info[5],'=')+1, strlen($info[5]));
$message = $message."<br><img src ='".$secondImg."' />";
}
$message = $message.'</body></html>';
if (mail($to, $subject, $message, $headers))
die ('Mail sent');
else
die ('Fail');
}else{
die ('Fail');
}
I am writing a simple program to send email. However, my mail content is not english based so I used utf-8 to encode.
When I changed the encode method, it can not send the processed html code, instead the mail content is the raw html code shown above, how to fix this problem?
If using PEAR lib is not a problem than you can look for Pear Mail-Mime lib to send mail or HTML contents. More details you can get from here - http://pear.php.net/manual/en/package.mail.mail-mime.example.php

Send email with just a jpg image

i need to send an email to some list with just a jpg as the body of the message, this are the headers i'm using, but it's not working when i add the image (instead, if i write some random text the email is sent correctly)
This is what i'm using so far:
message = '<img src="http://www.gulfview.info/admin/birthday_card_goes_here/birthday.jpg" width="600" height="800" />';
$subject = 'Happy Birthday from your Gulfview Friends !!';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From: Bob Fregalette <info#thegiftstores.org>' . "\r\n";
if(!mail($email, $subject, $message, $headers)){
echo $email." not sent <br>";
}
else {
echo $email ."Sent succesfully<br>";
}
Any hint?
Thanks
I'm assuming you've assigned something to the value of $email somewhere else?
Your code works as written for me if I assign something to the $email value before this code.
If I run it without a value of $email, it has a fatal error that there's no recipient message in the message header.

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
}

Categories