Welcome to Mysite

Using the PHP mail function I need to send out an email that includes a link back to a record that has been modified, the link will need to contain the $id of the record that was modified on the database. So far I have the email built, however am not sure on how I can include the link with variable.

mail('test@domain.com', 'Visitor Record Updated', "Hello,\r\n\r\nThe visitor record for " . $firstname . " " . $lastname . " Has been updated.\r\n\r\nYou can view the changes" . $url ."\r\n\r\nThank You"); 

That is how I plan to have the email sent, however how can i build the $url variable so that it sends the link as

http://app.site.com/visitor-view.php?id=$id 

2 Answers 2

mail('test@domain.com', 'Visitor Record Ppdated', "Hello,\r\n\r\nThe visitor record for " . $firstname . " " . $lastname . " Has been updated.\r\n\r\nYou can view the changes: http://app.site.com/visitor-view.php?id=" . $id ."\r\n\r\nThank You"); 

You can send simple link. But it may not clickable in some email provides. So You have to send as html email:

Refer below link for more details

http://css-tricks.com/sending-nice-html-email-with-php/ 

If you want to add CSS, then you can add as inline style.

From above link i prepared for your question:

$content =" 

Hello,

The visitor record for " . $firstname . " " . $lastname . " Has been updated.

You can view the changes Here

Thank You

"; $to = 'test@domain.com'; $subject = 'Visitor Record Updated'; $headers = "From: noreply@domai.com\r\n"; $headers .= "Reply-To: info@yourdomain.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to, $subject, $content, $headers);

Источник

I am trying to send a html link in mail using php. But I am getting the full text of html in the mail. Below is the code what I have tried . But it is not working. Any help is appreciated.

$emailid = $_POST['email']; $phoneno = $_POST['phoneno']; $to = "demoemail@gmail.com"; // this is your Email address $from = $emailid; // this is the sender's Email address $subject = "Intrested in scheduling appointment."; $message = "Click Here"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = "From:" . $from; $retval = mail($to,$subject,$message,$headers); 

2 Answers 2

I’ve checked with your code..

Seems like you are making a simple mistake.. You are not concatenating your code.. you are re assigning your header at line 3

$emailid = $_POST['email']; $phoneno = $_POST['phoneno']; $to = "demoemail@gmail.com"; // this is your Email address $from = $emailid; // this is the sender's Email address $subject = "Intrested in scheduling appointment."; $message = "Click Here"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = "From:" . $from; $retval = mail($to,$subject,$message,$headers); 
 $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From:" . $from; 

Update your header and try again!

Working code with template paste and run

   

Hi google

Just one more click

Activate Account

Kind Regards,
The google Team


google - The leading marketplace selling google.

This account notification was sent to you because you are a google user. Should you have any questions, you are welcome to email us.

Copyright © 2017 | google Pty Ltd. All rights reserved.

'; $header = "From:abc@gmail.com \r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-type: text/html\r\n"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) < echo "Message sent successfully. "; >else < echo "Message could not be sent. "; >?>

This question is in a collective: a subcommunity defined by tags with relevant content and experts.

Источник

User should get a email in the format:—— Copy the token: xxxxx And paste it in this Link —— My codes:

4 Answers 4

seems like your email function doesn’t have good react with html tags, you probably missing this in you’r $header object.

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

you want me to copy paste that context from this site ? the main problem is that people doesn’t google before they open new question.

No, you should add some code from that site and explain it how, why, when it works best of OP based on the link you are posting.

i googled a good many times. i tried as they said. even answers from stack overflow doesn’t work for me. but those answers worked for the askers.

There is many points you should think about them .. you can notice them in the following example code:

Link"; $random_hash = md5(uniqid(time())); $header = "From: $fromTitle \r\n"; $header .= "Reply-To: ".$emailFrom."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$random_hash."\"\r\n\r\n"; $header .= "This is token email.\r\n"; $header .= "--".$random_hash."\r\n"; $header .= "Content-type:text/html; charset=UTF-8\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; @mail($emailTo, $subject, $message, $header); ?> 

I don’t know why someone make vote down .. if there is some thing wrong just let us know .. my answer is tested and works correctly

yes i agree we must use variable for this .. i will change my answer .. and your function token_generator as i think should return the token and not echo the token

Upvoted. This is a great and complete answer. The only things I want to mention are: I think you are misusing boundary (see this article by Kevin McMahon: goo.gl/Li1jJ); and $from should be changed to $fromTitle in $header = «From: «.$from // . (I’ve submitted an edit to your answer for this). Aside from that, great answer. Prior to reading this, I didn’t even know about the multipart/mixed MIME type.

@SpencerDoak okay let me clear with you ,, i faced many problems before with send email ,, and after searching i found this as the best solution for me but i do not know what is the meaning of each stuff ,, you know ,, sometimes you do not have time ,, you just need to solve the issue and save your day .. i must read more about it 😉

There are some problems in your strings, however, here are a few things to consider here:

First all you might want to (just as a matter of practice) assign token_generator(10) to a variable on your script.

and pass $token to the script

Secondly you are having some trouble with the strings in your email. You don’t need to wrap your link in a href tags (in fact it will be a problem if the user does not have HTML email turned on (as many do not). Just post the link itself.

Thirdly, why not just attach the token to the URL? It’s an easier step for the user. Here’s an example:

$message="Follow this link: http://(url)recover_pass_get_mail.php?token=$token"; 

and then you can just get the token from the URL using

Источник

Include html in email

I suggest using PHPMailer, easy to use, takes care of all nesseccery headers, easy attachment sending, multiple recipients etc.

This supports multipart emails. +1 for being the only person to point to a solution that does that so far.

Set the correct headers (from php.net)

// To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); 

your $message may now contain HTML. For complex html/emails, it’s advisable to look at some packages such as the PEAR Mailer class for instance.

@Visa my code is taken straight from the PHP.net’s page on mail — have a good read of that and the comments.

I didn’t understand. You need to echo to the html like this ?

Or do you need to do this :

What’s exactly that you are trying to do ?

If you are trying to send HTML data via mail(), you need to set few headers

 $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf8' . "\r\n"; mail($to, $subject, $body, $headers); 

For more information — check http://php.net/manual/en/function.mail.php example 4

    

Here are the birthdays upcoming in August!

PersonDayMonthYear
Joe3rdAugust1970
Sally17thAugust1973
'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mary , Kelly ' . "\r\n"; $headers .= 'From: Birthday Reminder ' . "\r\n"; $headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?>

I also found this article useful:

@David, thanks, this is an example straight out of php.net as a stating point in answer to the ‘simple’ question!

This question is in a collective: a subcommunity defined by tags with relevant content and experts.

Источник

I am trying to use the mail function to send an email but can’t seem to get my link to work. It is displaying as a string instead of a link.. I am not sure how to closed off the string quotation or what the correct format is.

$company = 'pianocourse101@hotmail.com'; $subject = 'Account temporary suspended due to failed login attempts'; $mailTo = $row['user_email']; $headers = 'From: '.$company; $txt = "Hello ".$row['user_first']."" .$row['user_last']."! \n\n Your account has been temporary suspended because you or someone claiming to be you has failed to login into their account more than on more than five occasions. \n\n Please click on the following link to change your password so that you can login again Click here to reset your password "; mail($mailTo, $subject, $txt, $headers); 

you can just set www.yourdomain.com/reset.php as the link, i.e.: $txt = «Hello «.$row[‘user_first’] . $row[‘user_last’]. «! \n\n Your account has been. Please click link to login again: www.yourdomain.com/reset.php»;

If you want to fasten your development, don’t write stuff around mail , but rather use libraries like PHPMailer, SwiftMailer.

2 Answers 2

It looks like your mail is not in HTML format. I suggest you start using PHPMailer: https://github.com/PHPMailer/PHPMailer It’s really easy to use and In PHPMailer you can send HTML emails!

Here is their simple example:

SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'user@example.com'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above //Recipients $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient $mail->addAddress('ellen@example.com'); // Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); // Attachments $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; > catch (Exception $e) < echo "Message could not be sent. Mailer Error: ErrorInfo>"; > 

To install PHPMailer you can use composer. After installing composer you can install PHPMailer with composer like this:

composer require phpmailer/phpmailer 

or download the files manually

Источник

Читайте также:  Backup Database in PHP
Оцените статью