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

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/

Related

how can i redirect back to previous page after message sent from form [duplicate]

This question already has answers here:
Redirecting to previous page after login?
(18 answers)
Closed 2 years ago.
hi how can i send back to previous page in php
<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from. persons number is: ".$_POST['phone']." message is: ".$_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
?>
Try using php header function.
Example would be in PHP
header("Location: $_SERVER['HTTP_REFERER']");
Where $_SERVER['HTTP_REFERER'] by PHP.net is
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
<?php
$to = "email";
$subject = "mailed from";
$txt = $_POST['first-name']." ".$_POST['last-name']." sends message from.
persons number is: ".$_POST['phone']." message is:
".$_POST['message'];
$headers = "From: ".$_POST['email'];
mail($to,$subject,$txt,$headers);
// Redirect after mail
header("Location: $_SERVER['HTTP_REFERER']");
?>
Use can use this for redirections -
header("Location: pagename.php");
Replace pagename.php with your page.
Place it below mailing code so that it will redirect after the mail gets sent.

PHP email not sending to multiple recipients [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Sending mail to multiple recipients
(3 answers)
Closed 4 years ago.
After submitting a PHP form, I want an email to go to multiple recipients, but it does not. It goes to only the first address. It says in the email (in the "To" field that it is sending to the 3 addresses, but it is not. How can I add a CC or BCC to this code (if that is what is needed)? There are question about this on here and I've tried everything I've seen, but nothing is working so far. Thanks in advance.
Here is my code:
$headers = 'From: CBS Website';
$emailbody = 'Name: '.$_POST['name']."\n"
.'Company: '.$_POST['company']."\n"
.'Email: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Stage: '.$_POST['stage']."\n"
.'Budget Range: '.$_POST['budget']."\n"
.'Geographic Location: '.$_POST['location']."\n"
.'Permanent: '.$_POST['permanent']."\n"
.'Semi-permanent: '.$_POST['semi-permanent']."\n"
.'Special Considerations: '.$_POST['considerations']."\n"
.'Project Type: '.$_POST['projectType']."\n"
.'Square Footage: '.$_POST['sqfootage']."\n"
.'Number of Stories: '.$_POST['stories']."\n"
.'Schedule: '.$_POST['schedule']."\n"
.'SF Budget: '.$_POST['sfbudget']."\n"
.'Future Construction: '.$_POST['futureConst']."\n"
.'Special Features: '.$_POST['features']."\n"
.'Restrictions: '.$_POST['restrictions']."\n"
.'Referral: '.$_POST['referral']."\n";
mail("joedoe#domain.com,janedoe#domain.com,jimmy80#domain.com",'Contact Form Submission', $emailbody, $headers);
echo "<meta http-equiv='refresh' content=\"0; url=thankyou.php\">";

Sentmail To send a URL

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

How to make form fields required? [duplicate]

This question already has answers here:
Making email field required in php [closed]
(4 answers)
Closed 8 years ago.
I have this existing code and I am wondering how to make the name and email field required?
<?php
if(isset($_POST['submit'])){
$to = "xxx#email.com"; // this is your Email address
$from = $_POST['gift_email']; // this is the sender's Email address
$first_name = $_POST['gift_name'];
$subject = "Free Gift Request";
$msg = "A free gift has been requested from the following:"."\n";
$msg .= "Name: ".$_POST["gift_name"]."\n";
$msg .= "E-Mail: ".$_POST["gift_email"];
$headers = "From:" . $from;
mail($to,$subject,$msg,$headers);
//echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header('Location:free_program_thankyou.php');
}
?>
For form
<input type="text" name="gift_email" required>
<input type="text" name="gift_name" required>
For Php
if(empty($_POST['gift_email']))
{
echo 'This field is required';
}else {
//Do what you want to do here
}
A two basic ways to do this:-
Within the php program check each required form field has been filled in send a new page with an error message back if it is not. Be sure to return the contents of any fields already filled in or your users will wish a plague of boils on your person.
Validate in javascript. Have a function triggered by the "onsubmit" condition which checks for all required forms fields are filled and highlights any that are not. see here
In practice a robust web site will do both. This seems like duplication however the javascript function is much more responsive and user friendly, BUT, the php server side validation cannot be gamed by turning JS off or spoofing responses.

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.';

Categories