我的困境是使用php发送我的表单数据。 当然,我已经查看过多篇文章来解决这个问题。 在尝试调整我的代码以满足要求之后,我一直没有成功,因为php提交没有完成(我假设。) 具体来说,在点击提交后,下一页上没有显示内容,也没有弹出电子邮件窗口。 (我希望所有数据都显示在pop邮件窗口中。 如果只是html,css,jquery和php语言,我不会受到伤害。)
如果您需要查看html,我也很乐意发布它。
PHP - 代码
implementation - Implementation only dependencies for 'main' sources. (n)
+--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.1.4-2 (n)
+--- unspecified (n)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.4-2 (n)
+--- com.android.support:appcompat-v7:26.0.1 (n)
+--- com.android.support:design:26.0.1 (n)
+--- com.android.support.constraint:constraint-layout:1.0.2 (n)
+--- com.google.dagger:dagger:2.11 (n)
+--- io.reactivex.rxjava2:rxjava:2.1.3 (n)
+--- io.reactivex.rxjava2:rxkotlin:2.1.0 (n)
+--- io.reactivex.rxjava2:rxandroid:2.0.1 (n)
+--- com.costular:kotlin-utils:0.1 (n)
+--- android.arch.persistence.room:runtime:1.0.0-alpha9 (n)
+--- android.arch.persistence.room:rxjava2:1.0.0-alpha9 (n)
\--- com.android.support:support-v4:26.0.1 (n)
kapt
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
kaptAndroidTest
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
kaptDebug
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
kaptRelease
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
kaptTest
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
kaptTestDebug
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
kaptTestRelease
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.4-2
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.4-2
| \--- org.jetbrains:annotations:13.0
+--- com.google.dagger:dagger-compiler:2.11
| +--- com.google.dagger:dagger:2.11
| | \--- javax.inject:javax.inject:1
| +--- com.google.dagger:dagger-producers:2.11
| | +--- com.google.dagger:dagger:2.11 (*)
| | +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| | +--- com.google.guava:guava:21.0
| | \--- javax.inject:javax.inject:1
| +--- com.google.code.findbugs:jsr305:3.0.1 -> 1.3.9
| +--- com.google.googlejavaformat:google-java-format:1.3
| | +--- com.google.guava:guava:19.0 -> 21.0
| | \--- com.google.errorprone:javac:9-dev-r3297-1-shaded
| +--- com.google.guava:guava:21.0
| +--- com.squareup:javapoet:1.7.0 -> 1.8.0
| \--- javax.inject:javax.inject:1
\--- android.arch.persistence.room:compiler:1.0.0-alpha9
+--- android.arch.persistence.room:common:1.0.0-alpha9
| \--- com.android.support:support-annotations:26.0.0
+--- android.arch.persistence.room:migration:1.0.0-alpha9
| +--- android.arch.persistence.room:common:1.0.0-alpha9 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
| \--- com.google.code.gson:gson:2.8.0
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.4-2 (*)
+--- com.google.auto:auto-common:0.6
| \--- com.google.guava:guava:18.0 -> 21.0
+--- com.squareup:javapoet:1.8.0
+--- org.antlr:antlr4:4.5.3
+--- org.xerial:sqlite-jdbc:3.16.1
\--- commons-codec:commons-codec:1.10
HTML - 这是HTML,它基本上是用户可用来填写基本信息的表单。解决此问题后,我将实现Javascript / jQuery脚本以在将表单提交给PHP之前验证表单。 同样,我只是在寻找PHP的解决方案,而不是javascripting。
<?php
if(isset($_POST['submit'])){
$to = "random@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$client = $_POST['client'];
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$date = $_POST['date'];
$checkin = $_POST['datepicker'];
$due = $_POST['duedate'];
$state = $_POST['state'];
$zip = $_POST['zipcode'];
$phone = $_POST['phoneno'];
$confirm = $_POST['confirm'];
$file1 = $_POST['file1'];
$file2 = $_POST['file2'];
$prime = $_POST['prime'];
$sec = $_POST['second'];
$tri = $_POST['third'];
$dim = $_POST['dimtype'];
$width = $_POST['width'];
$length = $_POST['length'];
$details = $_POST['details'];
$design = $_POST['design'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['details'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['details'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $client . ", we will contact you shortly.";
// Function to validate against any email injection attempts
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<form id="project_form" action="_php/mobile.php" method="post" autocomplete="on">
<label for="client">Project Name:</label>
<br />
<input type="text" class="val" placeholder="Ace Designs" name="client" id="client">
<br />
<label for="last_name">Last Name:</label>
<br />
<input type="text" class="val" placeholder="Earl" name="lname" id="lname">
<br />
<label for="first_name">First Name:</label>
<br />
<input type="text" class="val" placeholder="Torey" name="fname" id="fname">
<br />
<label for="email">Email:</label>
<br />
<input type="text" class="val" placeholder="YourAceDesigner@gmail.com" id="email">
<br />
<label for="date">Date:</label>
<br />
<input type="text" class="val" placeholder="03/07/2017" name="date" id="date">
<br />
<label for="checkin">Check-In Date:</label>
<br />
<input type="text" class="val" name="datepicker" id="datepicker">
<script>
$(function() {
$("#datepicker").datepicker({
minDate: -20,
maxDate: "+1M +10D"
});
});
</script>
<br />
<label for="checkin">Check-In Date:</label>
<br />
<input type="text" class="val" placeholder="03/14/2017" name="checkin" id="checkin">
<br />
<label for="state">State:</label>
<br />
<select name="state" id="state" style="margin:.1em 0em 1em .8em; width: 13.3em;">
<option value="blank">Select State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
<br />
<label for="zip">Zip Code:</label>
<br />
<input type="text" class="val" placeholder="99999 or 99999-99" name="duedate" id="zip">
<br />
<label for="phone">Phone No:</label>
<br />
<input type="text" class="val" placeholder="800-999-9999" name="phone" id="phone">
<br />
答案 0 :(得分:0)
这是我设法找到的完整答案,但这对我想要发生的事情有最好的结果。
<?php
if(isset($_POST['submit'])){
Project Name: <?php echo $_POST["client"]; ?><br />
Email: <?php echo $_POST["email"]; ?><br />
Date: <?php echo $_POST["date"]; ?><br />
Check-In: <?php echo $_POST["datepicker"]; ?><br />
Due Date: <?php echo $_POST["duedate"]; ?><br />
State: <?php echo $_POST["state"]; ?><br />
Zip: <?php echo $_POST["zipcode"]; ?><br />
Phone No: <?php echo $_POST["phoneno"]; ?><br />
Design: <?php echo $_POST["confirm"]; ?><br />
File1: <?php echo $_POST["file1"]; ?><br />
File2: <?php echo $_POST["file2"]; ?><br />
Color1: <?php echo $_POST["prime"]; ?><br />
Color2: <?php echo $_POST["second"]; ?><br />
Color3: <?php echo $_POST["third"]; ?><br />
Dimension Type: <?php echo $_POST["dimtype"]; ?><br />
Width: <?php echo $_POST["width"]; ?><br />
Length: <?php echo $_POST["length"]; ?><br />
Details: <?php echo $_POST["details"]; ?>
<br /><br />
Price: <?php echo $_POST["design"]; ?>
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
}
?>
答案 1 :(得分:-1)
我注意到您的代码中存在以下差异
$to = "random@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
该收件人地址具有硬编码的电子邮件地址,而发件人地址来自$_POST['email']
。请确保这是正确的......
请参考以下PHP邮件脚本,它也具有CC的功能。不需要两个邮件功能。
<?php
/* Simple Plain eMail */
$from = "support@bbminfo.com";
$to = "abc@gmail.com";
$email_cc = "info@bbminfo.com";
$email_bcc = "xyz@yahoo.com";
$subject = "Invitation for New YGen SEO Tool";
$message = "Dear User, We are very glad to inform and invite you, that BBM's YGen SEO Tool (bbminfo.com) is now ready to launch on 15th August, 2013.";
/* Header Information */
$header = "From: " . strip_tags($from) . "\r\n";
$header .= "Cc: " . strip_tags($email_cc) . "\r\n";
$header .= "Bcc: " . strip_tags($email_bcc) . "\r\n";
$header .= "Reply-To: " . strip_tags($from) . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/plain; charset=us-ascii\r\n";
$flg = mail($to, $subject, $message, $header);
if($flg == true) {
echo("Your message has been sent.");
} else {
echo("Failed to sent.");
}
?>
我认为它会对你有帮助......
请参阅以下链接,了解有关PHP Mail function
的更多信息答案 2 :(得分:-2)
在php中,某些时候邮件功能无法正常工作,最佳做法是使用易于实现的php邮件程序类,并为您提供大量空间。