dongtuojuan8998 2013-11-05 21:45
浏览 29
已采纳

从php文件发送并发送电子邮件到我的Gmail帐户

I am trying to send an email through this php file, I am using WAMP server. I couldnt find the php.ini files to edit them, I am running these .php files on my locaclhost. The following is the code, kindly have a look, The error I am getting is "Warning: mail(): SMTP server response: 550 The address is not valid. in C:\wamp\www\Test\dbregister.php on line 69"

<?php
// the following are for validating the inputs 

if (isset($_POST['name'])){
  if (ctype_alpha($_POST['name'])){
  $uname=$_POST['name'];}else{header('Location: register.php');};
}else{
  header('Location: register.php');
};

if (isset($_POST['pwd'])){
  $pwd=$_POST['pwd'];
}else{
  header('Location: register.php');
};

if (isset($_POST['email'])){
  if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  $email=$_POST['email'];}else{header('Location: register.php');};
}else{
  header('Location: register.php');
};

if (isset($_POST['sex'])){
  $sex=$_POST['sex'];
}else{
  header('Location: register.php');
};

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="user"; // Table name 
@mysql_connect("$host","$username","$password") or die("cannot connect"); 
@mysql_select_db("$db_name")or die("cannot select DB");

$name=$_POST['name'];
$pwd=$_POST['pwd'];
$email=$_POST['email'];
$gender=$_POST['sex'];

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(user_name, password, email)VALUES('$name', '$pwd',         '$email')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='first.php'>Back to main page</a>";
// everything till here works fine, I am able to see the data in the data base tables.
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;  // the email address would be taken from the another webpage
// Your subject
$subject="Your confirmation link here";
// From
$header="From: sushwanth.n@gmail.com";
// Your message
$message="Your Comfirmation link 
";
$message.="Test email 
";

// send email
mail($to,$subject,$message,$header);  // I am getting the error in this line.
//mail('sushwanth.n@gmail.com','Test Email','This is a test email.',"From:     sunnibaba1@gmail.com");
// I have used the above line too see if it works, but even that was showing and error
}

// if not found 
else {
echo "This email is already in use, If you are a registered user, clik below to login";
echo "<a href='login.php'>LOGIN</a>";
//echo " <form method="post" action="login.php"><input type="submit" name="login">    </form> ";
}
?>

Kindly let me know how to debug this and also if I need to include any other functions to get this working.

  • 写回答

1条回答 默认 最新

  • dqba94619 2013-11-05 22:19
    关注

    It might be that the SMTP server you're attempting to use requires authentication, something the native mail() command doesn't support. In this case, you'll need to use an external PHP class (ex. PHPMailer) and provide the SMTP server with valid credentials.

    The file you need to configure is probably sendmail.ini:

    make sure to include your email credentials and port

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?