Phone 号码未进入 Gmail 收件箱 - PHP

Phone number is not coming to gmail inbox - PHP

Phone 号码未进入 gmail 收件箱。 它在发送时显示一些错误消息(警告:第 84 行和第 61 行定义的 sendemail() 缺少参数 5)。使用来自 github 的 Phpmailer 文件夹。 试了很多东西还没解决。

<?php
  $msg = "";

  if (isset($_POST['submit'])) {

    require 'phpmailer/PHPMailerAutoload.php';

    function sendemail($to, $from, $fromName, $body, $phone, $attachment = "")// line 61 {
      $mail = new PHPMailer();
      $mail->setFrom($from, $fromName);
      $mail->addAddress($to);
      $mail->addAttachment($attachment);
      $mail->Phone = ($phone);// argument 5
      $mail->Subject = 'Naukriglobal.com - Email- Resume';
      $mail->Body = $body;
      $mail->isHTML(false);

      return $mail->send();
    }

    $name = $_POST['username'];
    $email = $_POST['email'];
    $body = $_POST['body'];
    $phone = $_POST['phone'];


    $file = "attachment/" . basename($_FILES['attachment']['name']);
    if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
        if (sendemail('hameed.basha278@gmail.com', $email, $name, $body, $phone, $file)) {
        $msg = 'Email sent!';
        sendemail('hamidsince1990@gmail.com', 'NEW', 'RESUME', 'hey, we have received new email');//line84
      } else
        $msg = 'Email failed!';
    } else
      $msg = "Please check your attachment!";
  }
?>

<form method="post" action="index.php" enctype="multipart/form-data">
      <input class="name1" type="text"  name="username" placeholder="Name..." required><br>
      <input class="email1" type="email"  name="email" placeholder="Email..." required><br>
      <textarea class="text1" name="body" placeholder="Message..." required></textarea><br>

    <input type="text" name="phone" maxlength="15" placeholder="phonenumber" required="true" class="tel-number-field long" />

  <h3 class="h3">Upload Resume </h3>
  <input class="fileattach" type="file" placeholder="upload resume" name="attachment" required><br></input>
  <input class="submit1" type="submit" name="submit" value="Send Email">
</form>

$phonesendmail 函数的必需参数。您需要为其提供一个值。

正在使用与 phone 键关联的 $_POST 值进行设置。这可能存在也可能不存在。使用 isset 函数检查该值是否已设置。

然后你有几个选择:

1.Provide 如果未设置 $phone 的默认值

$DEFAULT_PHONE = "800-555-1212";
...
$phone = $DEFAULT_PHONE
if (isset($_POST['phone'])) {
    $phone = $_POST['phone'];
}

2.Don如果未设置 $phone 则不传递值,并提供默认值作为函数的一部分

function sendemail($to, $from, $fromName, $body, $attachment = "", $phone = "800-555-1212")
...
if (!isset($_POST['phone'])) {
    if (sendemail('hameed.basha278@gmail.com', $email, $name, $body, $file)){
    ...
    }
    ...
} else
    if (sendemail('hameed.basha278@gmail.com', $email, $name, $body, $file, $phone)){
    ...
    }
    ...
}

3.Ensure 发布到此页面的值始终为 $_POST['phone']

提供值

也就是说,更改此页面之前的页面上的表单验证,以强制用户必须通过在 input:

<input type='tel' name='phone' id='phone' required />

1.) 在您的代码中 function sendemail 开始的地方 { 被注释掉了,希望您的代码是正确的。

2.) 将 phone 输入行更改为以下并重试

 <input type="tel" name="phone"> placeholder="phonenumber" required><br>