Insert PHP variable to href link in HTML - php

I am sending a confirmation mail to user to confirm his account. The confirmation mail is styled using HTML and has an href element which points the users to a PHP file where I do the confirmation process. This href link also needs to have a PHP randomstring attached, the same randomstring is saved in Database and is also sent to user so that the cross-checking can be done in PHP once the user clicks on it.
<td align="center" style="margin:0;text-align:center">
<a href="http://aliencreative.wehubs.com/new_alien/email.php?code=<?php echo $randomString; ?>"
style="font-size:21px;line-height:22px;text-decoration:none;color:#ffffff;font-weight:bold;
border-radius:2px;background-color:#0096d3;padding:14px 40px;display:block;
letter-spacing:1.2px" target="_blank">Confirm Alien account now!</a></td>
The PHP code includes the above HTML as follows.
<?php
$randomString=time();
//$random="http://aliencreative.wehubs.com/new_alien/email.php?code=".$randomString;
echo $random;
$to = 'sample#gmail.com';
$subject = "Confirmation mail";
// Get HTML contents from file
$htmlContent = file_get_contents("email_template.php");
// Set content-type for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: Alien creative control<alien#alien.com>' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Some problem occurred, please try again.';
endif;
?>
However, the PHP variable is't getting available in the link.

Please try this. Remove file_get_contents and use include with output buffer function. I think this will insert your variable to your template. Please check the below updated code. Anyway your method is not a secure. Please create more complicated random code
<?php
$randomString=time();
//$random="http://aliencreative.wehubs.com/new_alien/email.php?code=".$randomString;
echo $random;
$to = 'sample#gmail.com';
$subject = "Confirmation mail";
// Get HTML contents from file
ob_start();
include "email_template.php";
$htmlContent=ob_get_contents();
ob_end_clean();
// Set content-type for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: Alien creative control<alien#alien.com>' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Some problem occurred, please try again.';
endif;
?>

Related

Print contents of PHP file in email message / body

I want to write a PHP page to run on a cron job to email out the contents of a PHP page.
When trying this, I get the scripts included in the body of the email, not just the echoed out elements.
Here is the script I'm using below currently to try and include kpi.php in the email.
Any thoughts on how I can achieve this?
alternatively I'd be happy to grab a screenshot of the page.
Thanks
<?php
$to = "email#domai.com";
$subject = "Daily Update";
$message = include('kpi.php');
// 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: <no-reply#email.com>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Just include it beforehand and echo the variables needed into the body of the email

adding a hyperlink in a sms email

What I am trying to do is send a registration confirmation sms via email from my website. I have it working now but I want to make sure that people are putting in correct phone numbers and carrier data. When my message sends it will send the word link but its not clickable is there a way to make the link clickable?
Here is my code so far.
<?php
$to = $mobil.$carier;
$subject = 'Registration for'.$school .'Scholarships Page';
$message = "
<html>
<head>
<title>Registration Email</title>
</head>
<body>
<h1>Email Registration Confirmation</h1>
<p>Welcome".$first_name." ". $last_name."
<p>In order to finish your registration for the scholarship site you need a valid
text phone number.
<p>Please Click the link given to confirm your registration.</p>
<a href=\"http://scholarship_domain/scholarships/activate.php?id=".$active_mobil ."\">Link
</a>
<p>If you have problems please contact your counsellor at your school. </p>
</body>
</html>
";
// 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: <scholarships.gnspes.ca>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
What happens now is the message sends but the link is not clickable and only the words "link" show up in the message. I guess I could just make it a link that a person could copy and paste but I am wondering if there is a way to make it a true hyperlink?
Thanks for the help.
When sending an Email or SMS to a phone number the message is automatically changed into html on the phone. I was able to get a clickable link send to myself with the following code but I would suggest making the message that it sends a little bit shorter because this message has to be sent as a picture message. I sent it to myself using just 0000000000#vtevt.com and it worked but the message was too long to show all the info so I sent just the link part and it works.
<?php
$to = $mobil.$carier;
$subject = 'Registration for '.$school .' Scholarships Page';
$message = '
Email Registration Confirmation
Welcome '.$first_name.' '. $last_name.'
In order to finish your registration for the scholarship site you need a valid
text phone number.
Please Click the link given to confirm your registration.
http://scholarship_domain/scholarships/activate.php?id='.$active_mobil .'
If you have problems please contact your counsellor at your school.
';
$message = str_replace("\n.", "\n..", $message);
// 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: <scholarships.gnspes.ca>' . "\r\n";
mail($to,$subject,$message);
?>
Also there is no need to send headers in a text message if that's where your sending it to. And the subject doesn't work in a text. It only shows the email or website that it was send from.

want to send session values in url

hi i am taking values from a page and getting values in second page whihch is working correctly but i have to send the values in url
<?php
session_start();
$_SESSION["email_address"] = $_REQUEST["email_address"];
echo "Favorite color is " . $_SESSION["email_address"] . ".<br>";
//$errors = '';
$myemail = 'info#abcdef.com';//<-----Put Your email address here.
$to_go="abcdef#gmail.com";
$to = $to_go;
$email_subject = "Contact form submission: aaname";
$email_body = "You have received a new message. ".
" Here are the details: Kindly <a href='localhost/ci/email_wait.php?email_address='.echo $email_address.'&password'=.$password.'>
Click Here</a> to reset your password";
$headers = "From:". $myemail;
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
echo "Mail Sent. Thank you we will contact you shortly.";
?>
NOTE: This code will not work on localhost.
Check out PHP's documentation on string interpolation
You want something like:
$email = "something#somewhere.com";
$body = "Your email address is: $email, hooray!";
echo $body;
Which will output Your email address is: something#somewhere.com, hooray!
Why you echo $email_address and where you initialize your email_address proper way to do like this
$email_body = "You have received a new message. Here are the details: Kindly<a href='localhost/ci/email_wait.php?email_address='".$email_address."'&password='".$password."'>Click Here</a> to reset your password";
and you can also send mail from localhost through smtp settings and put headers also before mail like this
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

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.

why is my form submitting to an excel file?

Okay all, I have a form that I want users to fill out. When They click submit, I want the contents of this form to be put into a message, and I want the contents to be added to an excel file. Then I want the message that is sent to the recipient to have an attachment of that excel file. You will see partial mime code, I have no Idea how to use it, that was my attempt at figuring this out... Heres what I have so far:
I guess the main question is more specifically, what in the code is making the contents the user submits, automatically go into an excel file and attach itself to the email?
$date = $_POST['date'];
$org =$_POST['Org'];
$activity =$_POST['activ'];
$dofevent = $_POST['dateoe'];
$money= $_POST['amountreq'];
$name =$_POST['name'];
$email =$_POST['email'];
$phone =$_POST['pnumber'];
$dateneeded =$_POST['datenb'];
//bottom
$semester =$_POST['semester'];
$question7a =$_POST['7a'];
$question7b =$_POST['7b'];
$mime_boundary = "<<<--==+X[".md5(time())."]";
$headers .= "From: SAF Request Form ";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
//$headers .= " boundary=\"".$mime_boundary."\"";
$subject .="SAF Request Form";
//$message .= "This is a multi-part message in MIME format.\r\n";
//$message .= "\r\n";
//$message .= "--".$mime_boundary."\r\n";
//$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
//$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message ="this is where I put my message";
mail ("20valvesofturbo#gmail.com",$subject,$message, $headers);
if( mail( "20valvesofturbo#gmail.com", $subject, $message, $headers ) ) {
echo "<p>The email was sent.</p>";
}
else {
echo "<p>There was an error sending the mail.</p>";
}
// start of xcel spreadsheet and header-->
$reg = "../data/eforms/saf/reg.xls";
$ft = fopen($reg,'a');
fwrite($ft,"header information");
// start of information submitted by user
fwrite($ft, $org);
fwrite($ft,"user submitted data");
fclose($ft);
//adds all the data
// individual excell sheet
$reg = "../data/eforms/saf/names/$org.xls";
$ft = fopen($reg,'w+');
fwrite($ft,"blablabla");
fclose($ft);
?>
what this does is it submits the data and sends a message, but it sends the data in an unknown file format as an attachment. If you open it in excel, it has the contents of the message...
Thanks!
For generating MIME encoded messages, I suggest that you use the Pear::Mail_Mime package ( http://pear.php.net/package/Mail_Mime). As for generating an Excel file, you can have a look at http://pear.php.net/package/Spreadsheet_Excel_Writer; depending on the complexity of the data to put into Excel, you could possibly also use just a CSV file

Categories