【问题标题】:PHP: Trying to send an email form with variables and an IF statementPHP:尝试发送带有变量和 IF 语句的电子邮件表单
【发布时间】:2016-03-07 05:35:28
【问题描述】:

我正在尝试根据可用的变量更改电子邮件。

总共有 6 个操作 id,但 20 个(代码如下所示)与其他操作不同,需要机器码。

$email = 
if ($OperationID == 20)
    {
        'Machine: '.$machCode."\r\n".
    }
"JobID: ".$jobid."\r\n" . 
"PartID: ".$part_id."\r\n" .
"\nNote: ".$message."\r\n";
@mail($email_to, $email_subject, $email); 

如果没有“if 声明”,则可以发送如下所示的电子邮件

Machine:
JobID: 123456789
PartID: 123456789
Note: Test

我不想要这个,因为“机器”旁边有一个空格。我希望删除机器行,除非 OperationID 显然是 20。所以电子邮件如下所示:

JobID: 123456789
PartID: 123456789
Note: Test

我要怎么做才能让机器线只在 Operation 等于 20 时才被激活?

我目前收到此错误

`解析错误:语法错误,第 21 行 /var/www/ps_t/send_form_email.php 中的意外 T_IF 调用堆栈:0.0004 656768 1. {main}() /var/www/ps_t/punch.php:0 ` 与上面使用的代码。

提前致谢。

【问题讨论】:

    标签: php if-statement syntax


    【解决方案1】:

    试试这个代码

    $email = "";
    if ($OperationID == 20)
    {
         $email .= 'Machine: '.$machCode."\r\n";
    }
    $email .= "JobID : ".$jobid."\r\n" . 
              "PartID: ".$part_id."\r\n" .
              "\nNote: ".$message."\r\n";
    @mail($email_to, $email_subject, $email); 
    

    【讨论】:

      【解决方案2】:

      试试这个:

      $email = '';
      if ($OperationID == 20)
      {
              $email .= 'Machine: '.$machCode."\r\n";
      }
      $email .= "JobID: ".$jobid."\r\n" . 
                "PartID: ".$part_id."\r\n" .
                "\nNote: ".$message."\r\n";
      @mail($email_to, $email_subject, $email); 
      

      【讨论】:

        【解决方案3】:

        试试这个:

        if ($OperationID == 20)
        {  
            $email = "Machine: ".$machCode."\r\n".
                     "JobID: ".$jobid."\r\n" . 
                     "PartID: ".$part_id."\r\n" .
                     "\nNote: ".$message."\r\n";
            @mail($email_to, $email_subject, $email);
        }
        else
        {
            $email = "JobID: ".$jobid."\r\n" . 
                     "PartID: ".$part_id."\r\n" .
                     "\nNote: ".$message."\r\n";
            @mail($email_to, $email_subject, $email);
        }
        

        【讨论】:

          猜你喜欢
          • 2015-08-06
          • 2021-05-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-25
          • 2020-11-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多