如果姓名中有空格,则联系表格不发送 [英] Contact form doesn't send if there is a space in name

查看:85
本文介绍了如果姓名中有空格,则联系表格不发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看网站的联系表单,但是现在,如果发件人姓名(例如 John Smith)中有空格,则它不希望发送,仅在一个单词( John )。问题可能出在哪里,我对.php一无所知,但我正在寻找解决方法。

I am reviewing a contact form for a website, but right now it doesn't want to send if in the sender name (like "John Smith") have space, it only sends if it's just a single word ("John"). Where could the problem be, I don't know anything about .php, but I am finding my way around.

编辑:好的,这是代码

<?php


function sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message, $type = "plain", $cc = "", $bcc = "") {

    require_once "class.phpmailer.php";

    $mail = new PHPMailer();


        $mail->IsMAIL();




    $mail->CharSet = "UTF-8";
    $mail->From = $fromemail;
    $mail->FromName = $fromname;
    $mail->AddAddress($toemail, $toname);
    $mail->AddReplyTo($fromemail, $fromname);
    if ($cc) { 
        $cc = explode(", ", $cc);
        foreach ($cc as $ccaddress) {
            $mail->AddCC($ccaddress);
        }
    }
    if ($bcc) {
        $bcc = explode(", ", $bcc);
        foreach ($bcc as $bccaddress) {
            $mail->AddBCC($bccaddress);
        }
    }
    if ($type == "plain") {
        $mail->IsHTML(false);
    } else {
        $mail->IsHTML(true);

    $mail->Subject = $subject;
    $mail->Body = $message;

    if(!$mail->Send()) {
        $mail->ErrorInfo;
        $mail->ClearAllRecipients();
        $mail->ClearReplyTos();
        return false;
    } else {
        $mail->ClearAllRecipients(); 
        $mail->ClearReplyTos();
        return true;
    }

}
}


function descript($text, $striptags = true) {
// Convert problematic ascii characters to their true values
    $search = array("40","41","58","65","66","67","68","69","70",
        "71","72","73","74","75","76","77","78","79","80","81",
        "82","83","84","85","86","87","88","89","90","97","98",
        "99","100","101","102","103","104","105","106","107",
        "108","109","110","111","112","113","114","115","116",
        "117","118","119","120","121","122"
        );
    $replace = array("(",")",":","a","b","c","d","e","f","g","h",
        "i","j","k","l","m","n","o","p","q","r","s","t","u",
        "v","w","x","y","z","a","b","c","d","e","f","g","h",
        "i","j","k","l","m","n","o","p","q","r","s","t","u",
        "v","w","x","y","z"
        );
    $entities = count($search);
    for ($i=0; $i < $entities; $i++) {
        $text = preg_replace("#(&\#)(0*".$search[$i]."+);*#si", $replace[$i], $text);
    }
    $text = preg_replace('#(&\#x)([0-9A-F]+);*#si', "", $text);
    $text = preg_replace('#(<[^>]+[/\"\'\s])(onmouseover|onmousedown|onmouseup|onmouseout|onmousemove|ondblclick|onfocus|onload|xmlns)[^>]*>#iU', ">", $text);
    $text = preg_replace('#([a-z]*)=([\`\'\"]*)script:#iU', '$1=$2nojscript...', $text);
    $text = preg_replace('#([a-z]*)=([\`\'\"]*)javascript:#iU', '$1=$2nojavascript...', $text);
    $text = preg_replace('#([a-z]*)=([\'\"]*)vbscript:#iU', '$1=$2novbscript...', $text);
    $text = preg_replace('#(<[^>]+)style=([\`\'\"]*).*expression\([^>]*>#iU', "$1>", $text);
    $text = preg_replace('#(<[^>]+)style=([\`\'\"]*).*behaviour\([^>]*>#iU', "$1>", $text);
    if ($striptags) {
        do {
            $thistext = $text;
            $text = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $text);
        } while ($thistext != $text);
    }
    return $text;
}

$name=0;
$telefon=0;
$sender=0;
$syobshtenie=0;
$ename=0;
$etelefon=0;
$esender=0;
$esyobshtenie=0;

if($_POST['name']){
$name = "Запитване от ".$_POST['name'];
}
else { $name=1; $ename=1; }


if($_POST['sender']){
$sender = $_POST['sender'];
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $sender))
{
$sender="Email";
}
}

else { $sender=1; $esender=1; }

if($_POST['telefon']){
$telefon = $_POST['telefon'];
}


if($_POST['zapitvane']){
$zapitvane = $_POST['zapitvane'];
$syobshtenie = "<p>Запитване от ".$_POST['name']."
<br />Email: ".$sender."
<br />Телефон: ".$telefon."</p>".$zapitvane;
}

    else { $syobshtenie=1; $esyobshtenie=1; }


if($name=="Име"){ $ename=1; }
if($telefon=="Телефон"){ $etelefon=1; }
if($sender=="Email"){ $esender=1; }
if($syobshtenie=="Моля, въведете съобщение до нас"){ $esyobshtenie=1; }


if($ename==0 && $esender==0 && $esyobshtenie==0 && $etelefon==0){

sendemail("VillaDes", "info@konsumator.com", "", $sender, $name, $syobshtenie, "", "", "");

echo '
<div class="active-error"" style="margin-top:5px;">Съобщението Ви беше изпратено.<br /><br />Приятен ден!</div>
<script>
document.getElementById("contact").reset();
</script>';
}


else {
echo '
<div class="border-15"></div><div class="active-error"><b>Моля, въведете:</b></div><div class="border-8"></div>';

if($ename==1) { echo '<div class="active-error">Име</div><div class="border-8"></div>'; }
if($esender==1) { echo '<div class="active-error">Е-поща</div><div class="border-8"></div>'; }
if($etelefon==1) { echo '<div class="active-error">Телефон</div><div class="border-8"></div>'; }
if($esyobshtenie==1) { echo '<div class="active-error">Запитване</div>'; }  
}

                echo '<script type="text/javascript">
                $(document).ready(function() {
                $("#close-email").click(function () { $("#mailresult").hide("fast"); } );
                });
                </script>';

?>


推荐答案

在您发布的代码中调用:

In the code you post you call:

sendemail("VillaDes", "info@konsumator.com", "", $sender, $name, $syobshtenie, "", "", "");

您的sendemail函数接受:

Your sendemail function accepts:

sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message

因此 $ fromname 将用作您的电子邮件的主题,而formname将为空。
class.phpmailer.php应该处理
当您使用 $ name 作为 $ fromemail 空格可能是个问题(没有空格的名称可以是本地邮箱?)。

So $fromname will be used as the subject of your e-mail and formname will be empty. class.phpmailer.php should handle subjects with spaces, so i don't think this will be the problem. When you use $name as $fromemail spaces will be a problem maybe. (name without spaces can be a local mailbox??).

除此之外,您不需要该类。 phpmailer.php发送您的电子邮件
使用默认的邮件功能: http:/ /php.net/manual/zh-CN/function.mail.php

Beside all this you don't need the class.phpmailer.php to send your email. Use the default mail function: http://php.net/manual/en/function.mail.php

$headers = 'From: "'.$fromemail.'" <'.$fromname.'>' . "\r\n" .
'Reply-To: "'.$fromname.'" <'.$fromemail.'>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail('"VillaDes" <info@konsumator.com>',$syobshtenie, "", $headers);

这篇关于如果姓名中有空格,则联系表格不发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆