无法在电子邮件处理程序中添加空格,表格

时间:2018-09-10 17:50:37

标签: javascript php html

早上好

我正在尝试在表单上的单词上添加空格。这是一个示例:

Sample pic

例如,“引荐名称”和“电话号码”应为“引荐名称”和“电话号码”。

这是表格:

<div class="container">
            <div class="row" style="margin-top: -10px;">
                <div class="col-md-6 col-md-offset-3">
                    <h2>Referral Form <a style="font-size: 10px;" href="../index.php">Back to homepage</a></h2>
                    <p> Send your referrals using the form below and we will get back to you as early as possible. </p>
                    <form role="form" method="post" id="reused_form" enctype=&quot;multipart/form-data&quot; >
                        <div class="form-group">
                            <label for="name"> Your Name:</label>
                            <input type="text" class="form-control" id="name" name="name" required maxlength="50">
                        </div>
                        <div class="form-group">
                            <label for="email"> Referral's Name:</label>
                            <input type="text" class="form-control" id="email" name="referralname" required maxlength="50">
                        </div>
                        <div class="form-group">
                            <label for="email"> Referral's Email:</label>
                            <input type="email" class="form-control" id="email" name="email" required maxlength="50">
                        </div>
                        <div class="form-group">
                            <label for="email"> Referral's Phone Number:</label>
                            <input type="text" class="form-control" id="email" name="phonenumber" required maxlength="50">
                        </div>
                        <div class="form-group">
                            <label for="name"> Message:</label>
                            <textarea class="form-control" type="textarea" name="message" id="message" placeholder="Your Message Here" maxlength="6000" rows="7"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="name"> Upload Resumé:</label>
                            <input type="file" class="form-control" id="image" name="image" required>
                        </div>
                        <button type="submit" class="btn btn-lg btn-success pull-right" id="btnContactUs">Send! &rarr;</button>
                    </form>
                    <div id="success_message" style="width:100%; height:100%; display:none; "> <h3>Sent your message successfully!</h3> </div>
                    <div id="error_message" style="width:100%; height:100%; display:none; "> <h3>Error</h3> Sorry there was an error sending your form. </div>
                </div>
            </div>
        </div>

这是php代码:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )

 */
require_once './vendor/autoload.php';

use FormGuide\Handlx\FormHandler;


$pp = new FormHandler(); 

$validator = $pp->getValidator();
$validator->fields(['name', 'referralname', 'email', 'phonenumber'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->field('message')->maxLength(6000);


$pp->attachFiles(['image']);


$pp->sendEmailTo('angela.sales@teamspan.com', 'marjorie.bugayon@teamspan.com'); // ← Your email here

echo $pp->process($_POST);

private function compose_mail($post)
	{
		$content = "Form submission: \n\n";
		foreach($post as $name=>$value)
		{
			$content .= ucwords($name).":\n";
			$content .= "$value\n\n";
		}
		$this->mailer->Body  = $content;
	}

很抱歉,如果我的问题不好,请尽我所能提出一个好问题。

3 个答案:

答案 0 :(得分:1)

您可以这样做

private function compose_mail($post)
    {
        $content = "Form submission: \n\n";
        foreach($post as $name=>$value)
        {
            $content .= ucwords($name).":\n";
            $content .= "$value\n\n";
        }
        $content = str_replace("Referralname", "Referral Name", $content);
        $content = str_replace("Phonenumber", "Phone number", $content);
        $this->mailer->Body  = $content;
    }

答案 1 :(得分:0)

“推荐人姓名”是一个标签。这仅对用户交互有利。您的PHP代码永远都看不到。

“ referralname”是类型为“ text”的INPUT控件的名称。这就是您的代码所使用的。

您不能(或至少应该)在字段名称中添加空格和标点符号。不需要它们相同。

答案 2 :(得分:0)

我认为您要在电子邮件正文中该空间。因此,请尝试在php中添加以下两行:

        $content = str_ireplace('Referralname', 'Referral Name', $content);
        $content = str_ireplace('Phonenumber', 'Phone Number', $content);

        //right before this line:
        $this->mailer->Body  = $content;

Php函数str_ireplace将第二个字符串替换为第一个字符串,但仅在电子邮件正文中。

Str_ireplace或str_replace应该与您相同。前者不区分大小写,后者区分大小写。