Jump to content

[SOLVED] My PHP wont send to email.


focus

Recommended Posts

Whats wrong with my code?

This is meant to send form details to an email address

 

 

<?php

 

 

function is_valid_email($from_email)

{

    return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si', $from_email);

}

 

 

 

$to_mail = "[email protected]";

$subject = "Register";

$firstname.=$_POST['firstname']."\n" ;

$lastname.=$_POST['lastname']."\n" ;

$gender.=$_POST['gender']."\n" ;

$dob.=$_POST['dob']."\n" ;

$dancename.=$_POST['dancename']."\n" ;

$crewname.=$_POST['crewname']."\n" ;

$suburb.=$_POST['suburb']."\n" ;

$dancestle.=$_POST['dancestle'] ."\n" ;

$from_email.=$_POST['from_email'] ."\n" ;

$experience.=$_POST['experience'] ."\n" ;

 

$message = "

<html>

<head>

    <title>Dance Registration</title>     

</head>

 

<body bgcolor=#F3F3F3>

<TABLE CELLSPACING=2 CELLPADDING=2 BORDER=0>

<TR BGCOLOR=#FFFFFF>

    <TD COLSPAN=2></TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>First Name:</TD>

    <TD>$firstname</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>Last Name:</TD>

    <TD>$lastname</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>Gender:</TD>

    <TD>$gender</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>DOB:</TD>

    <TD>$dob</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>Dance Name:</TD>

    <TD>$dancename</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>Crew Name:</TD>

    <TD>$crewname</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>Suburb:</TD>

    <TD>$suburb</TD>

</TR>

<TR BGCOLOR=#FFFFFF>

    <TD>E-mail Address:</TD>

    <TD><$email_address</A></TD>

</TR>

 

<TR BGCOLOR=#FFFFFF>

    <TD>Experience:</TD>

    <TD>$experience</TD>

</TR>

<TR>

    <TD COLSPAN=2></TD>

</TR>

</TABLE>

 

</body>

</html>

";

   

 

$sent = mail($to_email, $subject, $message) ;

if($sent)

{print "Your mail was sent successfully."; }

 

else

{print "We encountered an error sending your mail"; }

 

?>

Link to comment
https://forums.phpfreaks.com/topic/136319-solved-my-php-wont-send-to-email/
Share on other sites

Please use the [ code] [ /code] (without the space in those tags) to post code in.

 

//$to_mail = "[email protected]"; change this to $to_email
$to_email = "[email protected]";
$subject = "Register";
$firstname.=$_POST['firstname']."\n" ;
$lastname.=$_POST['lastname']."\n" ;
$gender.=$_POST['gender']."\n" ;
$dob.=$_POST['dob']."\n" ;
$dancename.=$_POST['dancename']."\n" ;
$crewname.=$_POST['crewname']."\n" ;
$suburb.=$_POST['suburb']."\n" ;
$dancestle.=$_POST['dancestle'] ."\n" ;
$from_email.=$_POST['from_email'] ."\n" ;
$experience.=$_POST['experience'] ."\n" ;

But then how does it know to which email to send it to?

 

The point was in the mail function, you were using $to_email, and in your variable declaration you were using $to_mail, since $to_mail is not the same as $to_email you needed to switch one. I chose to switch the $to_mail, to be $to_email.

 

Look at the line below the // it is not $to_email.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.