Jump to content

problem


sphinx

Recommended Posts

Hello,

 

What i'm trying to do is generate a random email like: something@website.com

 

Why isn't this working:

 

<?php
function genRandomString() {
    $length = 10;
    $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;
    $string = ”;    

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    }



$to = "email@email.com";
$subject = "Important";
$message = "Cheap goods available, user";
$from = "$string@website.com"
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

 

Many thanks

Link to comment
Share on other sites

ok thanks,

 

I put it to this:

 

$from = $string."@website.com";

 

Other info:

 

    mail("$email", "$subject",
    $message, "From:" . $from);
    $headers = "From:" . $from;

 

When I tested it, the email 'from' field displays as:

 

@website.com

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

A) You are not even calling your function.

 

B) As xyph posted, you have a variable scope problem. The $string variable you set inside your function does not exist outside the function. You need to return the result that your function produces.

 

C) What phily245 posted are two different syntaxes that produce the exact same result and don't have anything to do with your problem.

 

D) You should have php's error reporting set to E_ALL and display_errors set to ON so that php will help you by displaying all the errors it detects. You will save a TON of time. You would be getting an undefined error message at the $string variable in your main code, alerting you to the fact that it has not been set (see items A and B in this list.)

Link to comment
Share on other sites

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.