Jump to content


Photo

php mail function question


  • Please log in to reply
9 replies to this topic

#1 jmcall10

jmcall10
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 June 2006 - 04:33 PM

I have this code

$to = "email@emailaddress.com";
$subject = "Test email";
            
$message = "$mailMessage";
            
$headers = "From: email@emailaddress.com";
$headers .= "\nReply-To: email@emailaddress.com";
            
$sentOk = mail($to,$subject,$message,$headers);


I have $mailMessage as a text area input.

The email sends ok but what I want it to do is for me to be able to put html code in the text area.

i.e if I put
<a href="http://www.phpfreaks.com">phpfreaks</a>

I want it to be read like [a href=\"http://www.phpfreaks.com\" target=\"_blank\"]phpfreaks[/a]

any ideas

Thanks in advance

jmcall10

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 13 June 2006 - 04:56 PM

Just add this to the header
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and you should be able to send html

NoGray.com


#3 jmcall10

jmcall10
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 June 2006 - 05:14 PM

Thanks for that however I have a strange problem

When I use

<a href="http://www.phpfreaks.com>phpfreaks</a>

The link is clickable in outlook

but when I view the email in hotmail the link is the colour of a link but is not clickable?

I have checked hotmail settings and cant find anything

also when I check lycos mail it is not even the colour of a link?

Any ideas

thanks in advance

jmcall10

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 13 June 2006 - 05:27 PM

You're missing the second quotation mark on the <a> replace your link with:
<a href="phpfreaks.com">phpfreaks</a>
or something like that.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#5 jmcall10

jmcall10
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 June 2006 - 05:32 PM

Yeah I just type that one up for an example that wasnt the one Im using

The code in the one I use has both quotation marks

Thanks in advance

jmcall10

#6 jmcall10

jmcall10
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 June 2006 - 06:05 PM

Here is the new code I have.

Can someone tell me whats wrong

$to = "email@emailaddress.com";
$subject = "$mailSubject";

$message = "$mailMessage";

$headers = "From: email@emailaddress.com";
$headers .= "\nReply-To: email@emailaddress.com";
$headers .= "\nMIME-Version: 1.0";
$headers .= "\nContent-type: text/html; charset=iso-8859-1";

$sentOk = mail($to,$subject,$message,$headers);


Thanks in advance

jmcall10

#7 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 13 June 2006 - 06:19 PM

Hotmail usually disable HTML content unless you click enable HTML content (I think that's what it's called).

It's not your script, but hotmail filters.

NoGray.com


#8 jmcall10

jmcall10
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 June 2006 - 06:51 PM

So how come any other email I get via hotmail the links work?

#9 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 13 June 2006 - 07:01 PM

There are a lot of factors when it comes to filtering email.

It depends if the email in the Junk folder or the inbox. If the sender in a black list, or not, the IP address of the sender, the headers, the format of the message.
In your message, try to add
<html>
<head>
<title>Message</title>
</head>
<body>

YOUR Message

</body>
</html>

Even though everything above the body tag get stripped, this should lower the spam filter points.

NoGray.com


#10 jmcall10

jmcall10
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 13 June 2006 - 09:50 PM

ok still no such luck.

I will post all the code within the function I use and maybe it will make more sense

If someone could try it out I wud be much appreciated

I have a database with a table called 'mail_members2'

in the table are 3 fields:

'mail_id', 'mail_name' and 'mail_address'

The code takes in the subject and the text and mails it out to all in table.
Only thing that doesnt work for me is when I use html link code.

function newsletter(){
global $config, $subject,$mailSubject, $message, $mailMessage;
    if (is_loggedin()) {
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            if ($mailSubject == "" || $mailMessage == "") {
        echo "
            <html>
            <body>";
            
                        
        echo"
        We are sorry but the subject or message field was empty!
        </body>
        </html>";
        
} else {
    mysql_connect($config['sql_host'], $config['sql_username'], $config['sql_password']);
        mysql_select_db($config['sql_database']);
            
            $query = mysql_query("SELECT * FROM `mail_members2`");
            $num_rows = mysql_num_rows($query);
                
    
        while ($row = mysql_fetch_array($query)) {
            
            $to = "$row[mail_address]";
            $subject = "$mailSubject";
            
            $message = "Hey " . $row[mail_name]."<br>";
            $message .= "$mailMessage";
            
            $headers = "From: admin@somesite.com";
            $headers .= "\nReply-To: admin@somesite.com";
            $headers .= "\nMIME-Version: 1.0";
            $headers .= "\nContent-type: text/html; charset=iso-8859-1";
            
            $sentOk = mail($to,$subject,$message,$headers);
            }
        
        
        echo "
            <html>
            <body>";
            
            echo"
                NewsLetter has been sent!         
            </body>
            </html>";
    }
        
        
        
} else {
        echo "
            <html>
            <body>";
                        
            
        echo"
        <form method=\"post\" action=\"?act=newsletter\">
            <table>
                <tr>
            <td >Subject:</td>
            <td ><input type=\"text\" name=\"mailSubject\" size=\"20\"></td>
                </tr>
                <tr>
            <td >Message:</td>
            <td ><textarea rows=\"19\" name=\"mailMessage\" cols=\"60\"></textarea></td>
                </tr>
            
            </table>
            <input type=\"submit\" value=\"Send NewsLetter\" >
            </body>
            </html>";
    }
} else {
        echo "
            <html>
            <body>
            You are not logged in.

            </body>
            </html>";
    }

}


The code is part of a larger set of code that requires a log in. Simply strip the code accordingly

I would really appreciate help on this matter

Thanks in advance

jmcall10




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users