Sentmail To send a URL - php

I use php to send an email reseting a password.
<?php session_start(); ?>
<?php
if($_POST['UserEmail'] == '')
{
$_SESSION['error']['UserEmail'] = "E-mail is required.";
}
else
{
//whether the UserEmail format is correct
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['UserEmail']))
{
//if it has the correct format whether the UserEmail has already exist
$UserEmail= $_POST['UserEmail'];
$to = $UserEmail;
$subject = "Forgotten Password";
$header = "Change your password using the link below";
$message = "http://www.yourname.com/confirm.php?UserEmail=$UserEmail&5832572895237532897523875";
$sentmail = mail($to,$subject,$message,$header);
}
}
?>
I want the $message to be a clickable link how do i do this.
This is using WAMPs default mailing system.
cheers
I Have tried adding an anchor tag but that sends the anchor aswell not just the clickable link
using
$Message="<a href=http://www.yourname.com/confirm.php?UserEmail=James#email.co.uk&5832572895237532897523875>click here</a>" Doesnt work either any suggestions
Fix Found
basically it was fine just leaving the link in without any anchor tags.
$message="http://www.sitename.com/this.php?Username=email#email.com&432941482401284"
will display a clickable link inside your email.
Sorry for that

use anchor tag to make it clickable and assing it to $message:-
$message= "<a href='http://www.yourname.com/confirm.php?UserEmail=".$UserEmail."&5832572895237532897523875'>Click Here</a>";

$header is the mail-header containing non-display-values.
for example:
From: Your Name <you#example.com>\r\n
Reply-To: Max Muster <max#example.com>\r\n
(\r\n are the escaped characters)
There you also set the content-type:
Content-Type: text/html; encoding: utf-8\r\n
With this you can use html to design your mail and use <a>-tags for your links.
More Information: http://en.wikipedia.org/wiki/Email#Message_Header (Or if you are German: http://de.wikipedia.org/wiki/Header_(E-Mail) )
Everything, that does not belong to the header described in that links, has to be in the message-content, so in your $message. That includes your "click on that link below".
For address-checking take a look at http://php.net/manual/de/function.filter-var.php

Related

how can i style a sending email with inline css [duplicate]

This question already has answers here:
Php mail: how to send html?
(5 answers)
Closed 5 years ago.
I 'm using a single form to allow my guests subscribe on my upcoming website.
My problem is that i really dont know how to make this email has some css style. I tried inline css but nothing happens. The email i receive just display the code of styling and it doesnt transform it into html!
The code i use is this:
<?php
if(isset($_REQUEST["isvalid"])){
$youremail = "info#mywebsite.com;
$usersemail = $_POST["usersemail"];
$mailsubject = "You have a new subscriber";
$message ="
<div style='width:300px;padding:20px;margin:0 auto;background:#84C318;color:#ffffff;border-radius:3px;'>
Email Address: $usersemail
</div>
";
$headers = 'From:' . $usersemail . "\r\n";
mail($youremail, $mailsubject, $message, $headers);
echo "success";
} else {
echo "failed";
}
?>
I am not sure but i think i can add inline css style inside a variable. i also tried to move the inline style outside the variable but i got the same result.
Need some help here..
You need to specify that your email is a html email by setting the Content-type header to "text/html".
More information here: https://css-tricks.com/sending-nice-html-email-with-php/

Want to use href inside php variable [duplicate]

This question already has answers here:
How to send HTML/CSS emails?
(4 answers)
Closed 8 years ago.
I need to send a verification email, its working fine. But i don want to show the "link" in the email i just need to show some text like "click here to verify"
{
$verify_email="
Hello,
Thank you for signup.
For verify e-mail go to this http://".$site_url."/verify.php?user=%s&key=%s;
Or enter your verify code on verification page. Code is: %s
Thanks you.
";
}
This sends a email like the below
Hello,
Thank you for signup.
For verify e-mail go to this http://testsite.com/verify.php?user=username&key=de94569d40077060f5f5eb;
But i need this to be
Hello,
Thank you for signup.
For verify e-mail click here
Please help me
{
$verify_email="
Hello,
Thank you for signup.
For verify e-mail <a href='http://".$site_url."/verify.php?user=%s&key=%s> go to this </a>
Or enter your verify code on verification page. Code is: %s
Thanks you.
";
}
This is regular HTML markup. Use the anchor tag and enclose your URL in the href attribute.
Use this code
<?php
$to = 'your recipients';
$subject = 'Your subject';
$message = 'Your html code';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
?>
Try this
$verify_email='
Hello,
Thank you for signup.
For verify e-mail go to this Click here
Or enter your verify code on verification page. Code is: %s Thanks you.';

PHP : Read GMAIL Email with imap

here's my problem: I have a mailbox where came from 2 types of email:
1) e-mail with plain text
2) email, I think, base64-encoded text / html
I have a simple page in php that goes to read this email box, and prints out an HTML table with some information of each email
I recognize the two types of email from the object of the email, in the first case I have no problems, while in the second i have a problem
i read the "body" of the mail of the first type in this way (and I have no problem, I can print the contents of the email as plain text) :
$id = imap_uid($stream ,$email_id);
$message = imap_qprint(imap_body($stream, $email_id,FT_PEEK));
but in the second case it does not work this way, and I have tried the following
$message = imap_fetchbody($stream,$email_id,"");
$message = imap_fetchbody($stream,$email_id,"0");
$message = imap_fetchbody($stream,$email_id,"1");
$message = imap_fetchbody($stream,$email_id,"1.1");
$message = imap_fetchbody($stream,$email_id,"1.2");
$message = imap_fetchbody($stream,$email_id,"2");
echo "*".base64_decode($message)."*";
echo "*".imap_base64($message)."*";
but I have no result

Ajax contact form and UTF-8

i'm using ajax contact form, downloaded from: http://youhack.me/2010/07/22/create-a-fancy-contact-form-with-css-3-and-jquery/
Everything works ok except UTF as i can't use cyrilic symbols when submitting.
The php:
$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender
$web = $_POST['web']; // Your website URL
$body = $_POST['text']; // Your message
$receiver = "receiver#domain.com" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to
if (!empty($name) & !empty($email) && !empty($body)) {
$body = "Name: {$name}\n\nSubject: {$web}\n\nMessage: {$body}";
$send = mail($receiver, 'Contact from domain.com', $body, "From: {$email}");
if ($send) {
echo 'true'; //if everything is ok,always return true , else ajax submission won't work
}
}
It uses jquery.validationEngine-en for validation.
My html already has "Content-Type" content="text/html; charset=utf-8" in header.
I'm new to php and jquery, so i would appriciate some guidance to make UTF-8 work when submitting.
Thanks :)
Edit: When i try to use cyrilic chars (čšćđ) on a required field i get ajax input error "Please use letters only". If i submit the form with cyrilic chars on a non-required field, i receive and email, all letters show ok except cyrilic, which are like this: Å¡.
Edit 2: When i set the recipient to gmail (webmail), cyrilic chars show up ok, except in one field, where Ajax doesnt let me use them (regex from Reinder answer).
When i set recipient in outlook (local) and submit the form, none of the cyrilic chars don't show up ok, example: ÄĹĄ oÄa ĹĄ ÄŽŠÄÄ
SOLVED Thanks to Reinder for guide and David! Will solve it today :)
having looked at the plugin you're using, I think this has to do with the validation regex inside jquery.validationEngine-en.js
when the validation is set to 'onlyLetter' it will check using
/^[a-zA-Z\ \']+$/
and none of your characters čšćđ are allowed here...
you need to create a language validation javascript for the language you're using and change that regular expression. For example, have a look at this post
The next thing is to check the encoding of your PHP file and your headers.
Place this at the top of your PHP code
header("Content-type: text/html; charset=utf-8");
Check if the values are correctly displayed when just outputting them in PHP, like so:
echo $name;
If they are correctly displayed in the browser and it's just the email that's incorrectly displaying the characters, then you need to pass an encoding header to the email too
example:
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$body = "Name: {$name}\n\nSubject: {$web}\n\nMessage: {$body}";
$send = mail($receiver, 'Contact from domain.com', $body, $headers);
have a look at the mail function on the PHP.NET website
Rather than use the default PHP mail() function, I've found this come in handy when working with Japanese:
http://bitprison.net/php_mail_utf-8_subject_and_message

How can I add HTML formatting to 'Swift Mail tutorial based' PHP email?

I have developed a competition page for a client, and they wish for the email the customer receives be more than simply text. The tutorial I used only provided simple text, within the 'send body message'. I am required to add html to thank the customer for entering, with introducing images to this email.
The code is:
//send the welcome letter
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Thanks for entering the competition');
$message ->setFrom(array('info#examplemail.com' => 'FromEmailExample'));
$message ->setTo(array($info['email'] => $info['name']));
$message ->setBody('Thanks for entering the competition, we will be in touch if you are a lucky winner.');
$result = $mailer->send($message);
return $result;
}
This function.php sheet is working and the customer is recieving their email ok, I just need to change the
('Thanks for entering the competition,
we will be in touch if you are a lucky
winner.')
to have HTML instead...
Please, if you can, provide me with an example of how I can integrate HTML into this function.
You can also just add 'text/html' to setBody (ref):
->setBody($this->renderView('YouBundleName:Default:email.html.twig'), 'text/html');
$message = Swift_Message::newInstance();
$message->setContentType('text=html');
Will the same text remain or should it be styled somehow?
Editing your emails in html requires inline css styles eg:
('<p style="font-size:1.2em; color:#f0f0f0;">Thanks for entering the competition, we will be in touch if you are a lucky winner.</p>')
if you need a table just add:
('<table style="font-size:1.2em; color:#f0f0f0;"><tr><td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td></tr></table>')
or to make it more simpler
$message_body'
<table style="font-size:1.2em; color:#f0f0f0;">
<tr>
<td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td>
</tr>
</table>
';
$message ->setBody($message_body);
I know that when I need to send html emails I need to set the content-type to html which I believe you did on the following line
$body = format_email($info,'html');
I hope this is what you were looking for. if not let me know

Categories