Jump to content

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 = "blaaah@hotmail.com";

$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 = "blaaah@hotmail.com"; change this to $to_email
$to_email = "blaaah@hotmail.com";
$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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.