问题描述:

Hi I am creating a task assignment page, in which after creating the task admin can send a mail to assignee to know the task. I cant use PHP mail function since I cant configure office SMTP mail address. So I am using mailto function.

Issue happens when my Commenst got symbols like " &, ", ' . It will stop executing the remaining part of code

In my mail it just populates the first line. So my comments is getting broken.

Here is my code to mailto function :

<a href="mailto:'.mysql_result($result, $i, 'assignee').'@symantec.com?subject= Task Assignment &body= %0D%0AHello%20'.mysql_result($result, $i, 'assignee'). '%0D%0A%0D%0ADescription%20%3A%20'.mysql_result($result, $i, 'comments'). .'%20%0D%0A%0D%0A%0D%0AFor%20more%20details%20Log%20in%20to%20%3A%20%0D%0A " ><img src="images/mail.png" width="32" height="32" p = "center"></a>';

网友答案:

You put everything into one line which brings you into devils kitchen. Instead put the functionality apart (e.g. first load the data from the database), then process the data (e.g. build the mailbox name, the subject and the body) and then finally create the mail URL.

<?php

# load data from database
$assignee = mysql_result($result, $i, 'assignee');
$comments = mysql_result($result, $i, 'comments');

# process data
$mailbox = sprintf('%[email protected]', rawurlencode($assignee));
$headers = array(
    'subject' => 'Task Assignment',
    'body' => "Hello $assignee,\n\nDescription : $comments ...\n\nFor more details log in to ...",
);

# generate the mailto URL
$url = sprintf('mailto:%s?%s', $mailbox, http_build_query($headers));

You can then just output the $url:

printf('<a href="%s"><img src="images/mail.png" width="32" height="32" p="center"></a>',
        $url);
网友答案:

You need to explicity urlencode everything that is non alphanumeric.

Note, urlencode (the php command) doesn't urlencode everything such as underscore and letters and perhaps other things.

Example:

    $test="this: is it's dog/+_";
    echo "<br>";
    echo urlencode($test);
    echo "<br>";
    echo $test;

produces:

this%3A+is+it%27s+dog%2F%2B_
this: is it's dog/+_
相关阅读:
Top