-2

我有 2 段代码,我无法通过电子邮件表单发送邮件。我想我错过了我的 sendmail.php 文件。谁能帮我写这个或使用脚本来使用它?我拥有的代码是。

  var name = jQuery("input#name").val();
    if (name == "") {
  jQuery("span#name_error").show();
  jQuery("input#name").focus();
  return false;
}
  var email = jQuery("input#email").val();
  if (email == "") {
  jQuery("span#email_error").show();
  jQuery("input#email").focus();
  return false;
}

var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(email)) {
jQuery("span#email_error2").show();
jQuery("input#email").focus();
  return false;
}

var subject = jQuery("input#subject").val();

  var msg = jQuery("textarea#msg").val();
  if (msg == "") {
  jQuery("span#msg_error").show();
  jQuery("textarea#msg").focus();
  return false;
}

    var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
    //alert (dataString);return false;

  jQuery.ajax({
  type: "POST",
  url: "sendemail.php",
  data: dataString,
  success: function() {
    jQuery('#contactform').html("<div id='message'></div>");
    jQuery('#message').html("<strong>Contact Form Submitted!</strong>")
    .append("<p>We will be in touch soon.</p>")
    .hide()
    .fadeIn(1500, function() {
      jQuery('#message');
    });
  }
 });
return false;
});

});'

<div id="contactform">
                              <form id="contact" action="#">
                                  <fieldset>
                                      <span class="error" id="name_error">Please enter name !</span>
                                      <span class="error" id="email_error">Please enter email address !</span>
                                      <span class="error" id="email_error2">Please enter valid email address !</span>
                                      <span class="error" id="msg_error">Please enter message !</span>
                                      <label for="name" id="name_label">Your Name (required)</label>
                                      <input type="text" name="name" id="name" size="50" value="" class="text-input" />
                                      <label for="email" id="email_label">Your Email (required)</label>
                                      <input type="text" name="email" id="email" size="50" value="" class="text-input" />
                                      <label for="subject" id="subject_label">Subject</label>
                                      <input type="text" name="subject" id="subject" size="50"  value="" class="text-input" />
                                      <label for="msg" id="msg_label">Your Message (required)</label>
                                      <textarea rows="8" name="msg" id="msg" class="text-input"></textarea>
                                      <br />
                                      <input type="submit" name="submit" class="button" id="submit_btn" value="Send"/>
                                  </fieldset>
                              </form>
                        </div><!-- end contactform --> 

请帮忙。

4

2 回答 2

0

使用以下代码从您的发件人发送电子邮件

<?php
if(isset($_POST['submit']))
{
    $to = "someone@example.com"; // Replace This Id With Another ( Where U Need to Send )
    $subject = $_POST['subject']; // Enter A Subject..
    $message = 'Name : '.$_POST['name'].'<br/> Email : '.$_POST['email'].'<br/> Subject : '.$_POST['subject'].'<br/> Message : '.$_POST['msg'].' ';
    $from = $_POST['email'];
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
}
?> 

* 你需要$to用你的值替换值 * 例如,如果你需要发送邮件来abc@va.com使用它$to = "abc@va.com";

于 2013-01-10T06:30:33.903 回答
0

只需尝试以下示例:

发送邮件.php

<?php
$uname     =   mysql_real_escape_string($_POST['name']);
$uemail    =   mysql_real_escape_string($_POST['email']);
$usubject  =   mysql_real_escape_string($_POST['subject']);
$umsg      =   mysql_real_escape_string($_POST['msg']);
$to = 'john@gmail.com'; //Here add your to email where you have to sent after submitting the form
$subject = 'Test Mail';
$headers = "From: " . strip_tags($uemail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($uemail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>User Name :</strong> </td><td>".$uname."</td></tr>";
$message .= "<tr><td><strong>Email :</strong> </td><td>".$uemail."</td></tr>";
$message .= "<tr><td><strong>Subject :</strong> </td><td>".$usubject."</td></tr>";
$message .= "<tr><td><strong>Message :</strong> </td><td>".$umsg."</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to, $subject, $message, $headers);
echo "<strong>Contact Form Submitted!</strong>";
?>

我认为这可以帮助您解决问题。

于 2013-01-10T07:59:38.607 回答