Jump to content

[SOLVED] Basic Mail() Question


yuckysocks

Recommended Posts

Hi,

 

I'm looking to get this function to work:

 

mail('them@gmail.com', 'A new case study has been posted!', 'Go to <a href="admin.php">the admin page</a> to look it over. It is information regarding $schoolname', 'From: me@gmail.com');

 

The mail gets sent properly, but the link and the variable aren't treated properly. The message is in fact going to gmail, so maybe it has something to do with how they treat html in messages, but at least the variable ought to get filled in, eh?

 

It's a POSTed variable, do I need to call it that? Anyhow, thanks for your always prompt help.

 

Alex

Link to comment
Share on other sites

you probably need some headers like:

 

$headers = "From: someone@domain.com\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";
mail("them@gmail.com","A new case study has been posted!","Go to <a href="admin.php">the admin page</a> to look it over. It is information regarding $schoolname",$headers);

Link to comment
Share on other sites

if you are using any kind of html in the email then you have to change header to include it

<?php
$to = "them@gmail.com";
$subject = "A new case study has been posted!";
$headers = "From: me@gmail.com\r\n";
// used for html don't change
//leave the next 2 lines alone
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = "Go to <a href=\"admin.php\">the admin page</a> to look it over. It is information regarding $schoolname";

if(!mail($to, $subject, $message, $headers)){
echo "could not sent E-mail";
} else {
echo "Email sent";
}
?>

 

Ray

 

Link to comment
Share on other sites

I implemented Craygo's code. The variable is converted to the proper word, but the second header (Content-Type: text/html; charset=ISO-8859-1) is just displayed, as opposed to being used as a header. This prevents the link from being converted into a proper anchor element. Thoughts?

 

Thanks so much,

 

Alex

Link to comment
Share on other sites

Unfortunately, the second header is still displayed as text at the start of the email (the text/html char encoding one).

 

Any other ideas? This is not a huge deal, but I want the resulting email to be as useful as possible to the recipient (ie, just click a link instead of copy/paste it in).

 

Thanks again for the help,

 

Alex

Link to comment
Share on other sites

depending on where you send it, sometimes you will have problems with the carriage returns.

 

Try just using \n

 

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

 

Ray

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.