将 $_POST['url'] 添加到电子邮件 Pear 包的正文中?

Add $_POST['url'] to body of email Pear package?

我需要我的 php 脚本通过电子邮件向我发送一些已解析的变量。

当任何文本通过时,我都能正确收到电子邮件:

mypage.php?url=hello

但是如果 url 通过,我不会收到电子邮件:

mypage.php?url=http://www.google.com

我搜索了几个小时,但没有找到任何方法。

这是 php 脚本:

<?php
// Pear Mail Library
require_once "Mail.php";


$name = $_POST['name'];
$url = $_POST['url'];



$from = '<noreply@website.com>';
$to = '<me@gmail.com>';
$subject = 'Hi!';
$body = '


Name: '.$name.'
The url is: '.$url.'


';

            
$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);



$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'mail@gmail.com',
        'password' => 'password'
    ));


$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<h1>Message successfully sent!</h1>');
}

?>

解析实际 url 时,我没有收到电子邮件,但也没有显示任何错误。

正如@Xorifelse 所说,我使用了 addslashes 函数并且它起作用了。我正确地收到了包含 url 的电子邮件。

下面是工作脚本:

<?php
// Pear Mail Library
require_once "Mail.php";


$name = $_POST['name'];
$url = $_POST['url'];



$from = '<noreply@website.com>';
$to = '<me@gmail.com>';
$subject = 'Hi!';
$body = '


Name: '.addslashes($name).'
The url is: '.addslashes($url).'


';

            
$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);



$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'mail@gmail.com',
        'password' => 'password'
    ));


$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<h1>Message successfully sent!</h1>');
}

?>