doutiao2540 2018-11-24 13:20
浏览 41

如何在没有PHP邮件的情况下发送表单数据

I'm trying to figure out my issue, I have a shared hosting provide that had the PHP mail function disable for security reasons.

I need to send some forms data using PHP, I only know how to send form data using the PHP mail function.

I tried using phpmailer, got ir from GitHub, but it didn't worked.

My question is very simple, is there a workaround to send form data without the PHP mail function to bypass the disabled phpmail and nobody=on tweak on my shared web hosting?

<?php

function send_mail($email, $recipient_name, $message='')
{
    require("phpmailer/class.phpmailer.php");
    require("phpmailer/class.smtp.php");

    $mail = new PHPMailer();

    $mail->CharSet="utf-8";
    $mail->IsSMTP();                               
    $mail->Host = 'localhost';
    $mail->Port = 465;
    $mail->SMTPAuth = true;    
    $mail->Username = "user@mysite.com";
    $mail->Password = "password"; 

    $mail->setFrom($email, $recipient_name);
    $mail->AddAddress($email, $recipient_name);

    $mail->WordWrap = 50;                          
    $mail->IsHTML(false);                          

    $mail->Subject = "Contact form";
    $mail->Body    = $message;

   if(!$mail->Send())
   {
       echo "Message could not be sent. <p>";
       echo "Mailer Error: " . $mail->ErrorInfo;
       exit;
   }

   echo "Message has been sent";
}

//vars
$subject = "Contac form";

$from = $_POST['email'];

//data
$msg = "NAME: "  .$_POST['name']    ."<br><br>
";
$msg .= "EMAIL: "  .$_POST['email']    ."<br><br>
";
$msg .= "WEBSITE: "  .$_POST['website']    ."<br><br>
";
$msg .= "MESSAGE: "  .$_POST['message']    ."<br>
";

//Headers
$headers  = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=UTF-8
";


$mail="support@mysite.com";

//send mail
//mail($mail, $subject, $msg, $headers, "-f $from");
send_mail($from, $_POST['name'], $msg);

?>
  • 写回答

2条回答 默认 最新

  • douxin1884 2018-11-24 22:42
    关注

    In essence it all boils down to knowing the environment your shared hosting provider is giving you.

    Since they disable php's mail() function, I presume they are trying to not have to deal with spammers using their services.

    So they probably also will not run an SMTP service on localhost, and most likely will filter out outgoing traffic to port 25 to prevent you from delivering it on other mail servers as well. But again: they might not (yet).

    But it's worth checking out what is available:

    • Is there an SMTP service running on localhost ?
    • Is there any outgoing relay SMTP service they provide for their legitimate customers ?
    • Do they filter outgoing SMTP on port 25 to the rest of the world ?
    • Do they allow you to connect to authenticated SMTP services for delivery ?

    It's a bit of work and how to get the answers depend a lot on how minimal the service is that you get and what other resources you have around the internet. Anyway the easiest is to simply ask your supplier: they know what they allow, what they block and what they want to do next depending on where they are trying to get rid of spammers.

    Anyway, your best bet is to use authenticated delivery towards a google server with a destination address on gmail or so. That's the least likely to get filtered away by either Google or a shared hosting provider who know what they do. Take care: authenticated delivery means the webserver has a way to authenticate towards google, so if the separation between different customers is suboptimal (it's by far not always foolproof), your "neighbours" in the shared hosting can get to those credentials with relative ease, so make sure it's not an account you care about a lot - hence: create a gmail address just for that use...

    If they don't allow anything. You can still save the email on the server, retrieve it from a desktop or other server and send it from there with some programming.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度