Justin Cox
Justin Cox

Reputation: 3

PHP mail function not working properly

I have a PHP script that sends an email to a user based on form data they have entered, but when I include a variable in a string, all the email says is "0"

<?php
    $u_name = $_POST['u_name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $to = $_POST['email'];
    $subject = "Site Activation";
    $message = "Hello " + $u_name + ",";
    $from = "[email protected]";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
?>

Upvotes: 0

Views: 2149

Answers (2)

Alex
Alex

Reputation: 7688

Just as @MahdiParsa said, in PHP the concatenation is done with . But you may as well do de following (depends of each one's taste):

$firstVariable = "Hey";
$secondVariable = "How are you?";

$mixedVariable1 = $firstVariable . ' Alex! ' . $secondVariable;
$mixedVariable2 = "$firstVariable Alex! $secondVariable";
$mixedVariable3 = "{$firstVariable} Alex! {$secondVariable}";
  // $mixedVariable3 is the same as $mixedVariable2,
  // only a different type of Variable Substitution 
  // Take a look at:
    // http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html

http://codepad.org/1aYvxjiC

Upvotes: 0

A1Gard
A1Gard

Reputation: 4168

The php not add string with "+" use "." for concat string.

This is fixed code:

<?php
    $u_name = $_POST['u_name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $to = $_POST['email'];
    $subject = "Site Activation";
    $message = "Hello " . $u_name . ",";
    $from = "[email protected]";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
?>

Upvotes: 2

Related Questions