Jump to content

Archived

This topic is now archived and is closed to further replies.

jmcall10

php mail function question

Recommended Posts

I have this code

[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);

[/code]

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 [code]<a href="http://www.phpfreaks.com">phpfreaks</a>[/code]

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

any ideas

Thanks in advance

jmcall10

Share this post


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

Share this post


Link to post
Share on other sites
Thanks for that however I have a strange problem

When I use

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

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

Share this post


Link to post
Share on other sites
You're missing the second quotation mark on the <a> replace your link with:
<a href="phpfreaks.com">phpfreaks</a>
or something like that.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Here is the new code I have.

Can someone tell me whats wrong

[code]
$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);
[/code]


Thanks in advance

jmcall10

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
[code]
<html>
<head>
<title>Message</title>
</head>
<body>

YOUR Message

</body>
</html>
[/code]

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

Share this post


Link to post
Share on other sites
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.

[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>";
    }

}

[/code]

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

Share this post


Link to post
Share on other sites

×

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.