【问题标题】:Curl doesn't send any messageCurl 不发送任何消息
【发布时间】:2022-10-31 06:42:59
【问题描述】:

我有一种感觉,这与未发送的 url 值有关,但我是 php 新手,不知道使用什么类型的其他 url 来测试代码一切似乎都井井有条,因为代码已经磨损了一段时间以前,然后它停止工作。

请帮忙

<?php
$name=$_GET["name"];
$username=$_GET["username"];

$message= "
<b>name:</b>&nbsp;&nbsp;".$name."
<br><br>
<b>username:</b>&nbsp;&nbsp;".$username."
<br><br>";


$toone='example@gmail.com';
$totwo='example@gmail.com';

$subject = 'Response Data';


$url = 'http://smtpwebapi.com.ng';

//The data you want to send via POST
$fields = [
    'message' => $message, 
    'to1' => $toone, 
    'to2' => $totwo,
    'subject' => $subject
];

//url-ify the data for the POST
$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

//execute post
$result = curl_exec($ch);
echo $result;
?>

【问题讨论】:

    标签: php curl phpmailer php-curl


    【解决方案1】:
        require 'classes/Exception.php';
        require 'classes/PHPMailer.php';
        require 'classes/SMTP.php';
        $mail = new PHPMailer(TRUE);
        try {
            $mail->isSMTP();
            $mail->Host =  $smserver;
            $mail->SMTPAuth = $authtrue;
            $mail->Username = $smuser;
            $mail->Password = $smpass;
            $mail->Port = $smport;
            $mail->SMTPDebug =false;
            $mail->setFrom($from_email_address, $from_username);
            $mail->addAddress('to email address', $to_username);
            $mail->isHTML(true);
            $mail->Subject = 'subject of email';
            $mail->Body = 'your body part of email';
            $mail->send();
    
        }
        catch (Exception $e)
        {
            echo $e->errorMessage();
            die();
        }
        catch (Exception $e)
        {
            echo $e->getMessage();
            die();
        }
    

    这是我更改的工作代码。我在以下方面找到了帮助: https://fullstackuser.com/qs/24/send-email-using-the-gmail-smtp-server-from-a-php-page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多